{"id":473,"date":"2019-03-08T21:29:07","date_gmt":"2019-03-08T13:29:07","guid":{"rendered":"https:\/\/kaispace.cn\/?p=473"},"modified":"2019-03-08T21:29:07","modified_gmt":"2019-03-08T13:29:07","slug":"20190308%e5%a4%b4%e6%9d%a1%e4%ba%8c%e9%9d%a2%e5%87%89%e7%bb%8f","status":"publish","type":"post","link":"https:\/\/blog.kaispace.cn\/?p=473","title":{"rendered":"20190308\u5934\u6761\u4e8c\u9762"},"content":{"rendered":"<h1>\u7b2c\u4e00\u9898 \u7ed9\u51fa\u573a\u666f\u5199SQL,\u8bbe\u8ba1\u7d22\u5f15,\u8bbe\u8ba1\u7f13\u5b58<\/h1>\n<p>\u884d\u751fRedis\uff0cB+\u6811\uff0c\u7d22\u5f15\u6700\u5de6\u524d\u7f00\u539f\u5219\uff0cRedis ZSET,\u5e95\u5c42\u7684ziplist,skiplist<\/p>\n<h1>\u7b2c\u4e8c\u9898 \u6f14\u5531\u4f1a\u5b89\u6392 \u6c42\u51fa\u6700\u5927\u5b89\u6392\u573a\u6570\u548c\u5b89\u6392\u7684\u5bf9\u5e94\u65b9\u6848<\/h1>\n<pre><code class=\"language-java line-numbers\">public class VocalConcert {\n    static ArrayList&lt;int[]&gt; concert = new ArrayList&lt;&gt;();\n    static ArrayList&lt;String&gt; ans = new ArrayList&lt;&gt;();\n    public static void main(String[] args){\n        concertInit();\n        int maxCount = 0;\n        for(int i = 0;i&lt;concert.size();i++){\n            \/\/\u8bb0\u5f55\u4ece0-concert.size()-1\u4e3a\u8d77\u70b9\u7684\u6240\u6709\u60c5\u51b5\n            maxCount = Math.max(maxCount,findMax(i,i+1,1,String.valueOf(i)));\n        }\n        System.out.println(\"MAX COUNT \"+maxCount);\n        for(String s:ans){\n            if(s.length()==maxCount) {\n                System.out.println(s);\n            }\n        }\n    }\n\n    \/**\n     * \u521d\u59cb\u5316\n     *\/\n    private static void concertInit(){\n        concert.add(new int[]{1,10});\n        concert.add(new int[]{2,4});\n        concert.add(new int[]{4,6});\n        concert.add(new int[]{3,7});\n        concert.add(new int[]{5,7});\n        concert.add(new int[]{5,8});\n        concert.add(new int[]{3,8});\n        concert.add(new int[]{7,10});\n    }\n\n    \/**\n     * \u627e\u51fa\u6240\u6709\u7b26\u5408\u6761\u4ef6\u7684\u573a\u6b21\n     * @param lastIndex \u4e0a\u4e00\u6b21\u7684\u6f14\u51fa\u7d22\u5f15\n     * @param index \u5f53\u524d\u6f14\u51fa\u7d22\u5f15\n     * @param count \u5f53\u524d\u7684\u5b89\u6392\u6f14\u5531\u4f1a\u573a\u6570\n     * @param a \u6f14\u51fa\u7684\u5b89\u6392\n     * @return \u6700\u5927\u7684\u6f14\u51fa\u573a\u6570\n     *\/\n    private static Integer findMax(int lastIndex,int index,int count,String a){\n        int result = count;\n        if(index&gt;=concert.size()){\n            if (!ans.contains(a)) {\n                ans.add(a);\n            }\n            return result;\n        }\n        if(concert.get(lastIndex)[1]&gt;concert.get(index)[0]){\n            \/\/\u524d\u540e\u4e24\u573a\u6f14\u5531\u4f1a\u91cd\u53e0\n            while(index&lt;concert.size()){\n                index++;\n                result = Math.max(result,findMax(lastIndex,index,count,a));\n            }\n        }else{\n            \/\/\u524d\u540e\u4e24\u573a\u6f14\u5531\u4f1a\u4e0d\u91cd\u53e0\n            count+=1;\n            int curIndex = index;\n            while(index&lt;concert.size()){\n                \/\/\u4e0d\u91cd\u53e0 \u4ee5\u65b0\u7684\u60c5\u51b5\u5f80\u4e0b\u8d70\n                result = Math.max(result,findMax(curIndex,index+1,count,a+curIndex));\n                index++;\n            }\n        }\n        return result;\n    }\n}\n\n<\/code><\/pre>\n<h1>\u7b2c\u4e09\u9898 AB\u8d4c\u5f92 \u4e24\u6b21\u83b7\u80dc\u6982\u7387\u90fd\u662f0.5 A\u83b7\u80dc\u4e24\u4e2a\u5c0f\u573a\u6700\u7ec8\u80dc\u5229\uff0cB\u83b7\u80dc\u4e09\u4e2a\u5c0f\u573a\u6700\u7ec8\u80dc\u5229\uff0c\u6c42AB\u83b7\u80dc\u6982\u7387<\/h1>\n<pre><code class=\"language-java line-numbers\">public static void main(String[] args) {\n        \/**\n         * \u8fd9\u9898\u540e\u6765\u60f3\u4e86\u4e00\u4e0b\u5c31\u662f\u6c42\u51faA\u5c31\u53ef\u4ee5\u6c42\u51faB\u4e86\uff0c\u56e0\u4e3a\u5728aGamblerWinCount+bGamblerWinCount-1\u56de\u5408\u5185\u5c31\u80af\u5b9a\u4f1a\u7ed3\u675f\n         *\/\n        int min = aGamblerWinCount &gt; bGamblerWinCount ? bGamblerWinCount : aGamblerWinCount;\n        float a = 0;\n        int maxGameCount = aGamblerWinCount + bGamblerWinCount - 1;\n        \/\/\u516c\u5f0f\u4e3a 1\/2^index * [C index-1 min-1](\u7ec4\u5408) \u5373\u5728\u6700\u540e\u4e00\u4f4d\u5df2\u7ecf\u5b9a\u597d\u7684\u60c5\u51b5\u4e0b\uff0c\u6c42min-1\u4e2a\u80dc\u5229\u5728index-1\u5c40\u91cc\u9762\u7684\u7ec4\u5408\u6570\n        for (int index = min; index &lt;= maxGameCount; index++) {\n            a += Math.pow((double) 1 \/ 2, index) * tri((index - 1),min-1);\n        }\n        System.out.println(a);\n        System.out.println(1-a);\n    }\n\n    \/\/\u6768\u8f89\u4e09\u89d2\u6c42\u7ec4\u5408\n    static int tri(int x,int y){\n        if(x&lt;y){\n            return 1;\n        }\n        int[][] a = new int[x+1][x+1];\n        for(int i=1; i&lt;=x; i++ )\n        {\n            a[i][0] = a[i][i] = 1;  \/\/\u521d\u59cb\u5316\u7b2c\u4e00\u5217\u548c\u5bf9\u89d2\u7ebf\u4f4d\u7f6e\u5168\u4e3a1\uff0c\u5373\u6700\u4e24\u8fb9\u7684\u4f4d\u7f6e\n            for( int j=1; j&lt;i; j++ )\n                a[i][j] = (a[i-1][j] + a[i-1][j-1]) % 1007;\n        }\n        return a[x][y];\n    }\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c\u4e00\u9898 \u7ed9\u51fa\u573a\u666f\u5199SQL,\u8bbe\u8ba1\u7d22\u5f15,\u8bbe\u8ba1\u7f13\u5b58 \u884d\u751fRedis\uff0cB+\u6811\uff0c\u7d22\u5f15\u6700\u5de6\u524d\u7f00\u539f\u5219\uff0cRedis ZSET,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.kaispace.cn\/index.php?rest_route=\/wp\/v2\/posts\/473"}],"collection":[{"href":"https:\/\/blog.kaispace.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kaispace.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kaispace.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kaispace.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=473"}],"version-history":[{"count":0,"href":"https:\/\/blog.kaispace.cn\/index.php?rest_route=\/wp\/v2\/posts\/473\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.kaispace.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kaispace.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kaispace.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}