{"id":4720,"date":"2020-02-04T15:25:31","date_gmt":"2020-02-04T07:25:31","guid":{"rendered":"https:\/\/www.xttblog.com\/?p=4720"},"modified":"2020-02-04T15:25:31","modified_gmt":"2020-02-04T07:25:31","slug":"%e7%ae%80%e5%8d%95%e7%99%be%e8%a1%8cjava%e4%bb%a3%e7%a0%81%e8%a7%a3%e4%b8%96%e7%95%8c%e6%9c%80%e9%9a%be%e4%b9%9d%e5%ae%ab%e6%a0%bc","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4720","title":{"rendered":"\u7b80\u5355\u767e\u884cJava\u4ee3\u7801\u89e3\u4e16\u754c\u6700\u96be\u4e5d\u5bab\u683c"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4e16\u754c\u6700\u96be\u4e5d\u5bab\u683c\u5230\u5e95\u6709\u591a\u96be\uff1f\u636e\u8bf4\uff0c\u5f88\u591a\u6570\u5b66\u5bb6\u90fd\u641e\u4e0d\u5b9a\uff01\u771f\u7684\u662f\u8fd9\u6837\u5417\uff1f\u4eca\u5929\u6211\u4eec\u4e00\u8d77\u6765\u4f7f\u7528 Java \u641e\u5b9a\u5b83\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u82ac\u5170\u6570\u5b66\u5bb6\u56e0\u5361\u62c9\u82b1\u8d39 3 \u4e2a\u6708\u8bbe\u8ba1\u51fa\u4e86\u4e16\u754c\u4e0a\u8fc4\u4eca\u96be\u5ea6\u6700\u5927\u7684\u6570\u72ec\u6e38\u620f\uff0c\u800c\u4e14\u5b83\u53ea\u6709\u4e00\u4e2a\u7b54\u6848\u3002\u56e0\u5361\u62c9\u8bf4\u53ea\u6709\u601d\u8003\u80fd\u529b\u6700\u5feb\u3001\u5934\u8111\u6700\u806a\u660e\u7684\u4eba\u624d\u80fd\u7834\u89e3\u8fd9\u4e2a\u6e38\u620f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u521a\u597d\uff0c\u524d\u6bb5\u65f6\u95f4\uff0c\u4e00\u5219\u817e\u8baf\u7684\u65b0\u95fb\u79f0\u4e2d\u56fd\u8001\u5934\u4e09\u5929\u7834\u89e3\u4e16\u754c\u6700\u96be\u4e5d\u5bab\u683c\uff0c\u867d\u7136\u6700\u540e\u8001\u4eba\u662f\u6539\u4e86\u4e00\u4e2a\u6570\u5b57\uff0c\u4f46\u662f\u5f15\u8d77\u4e86\u591a\u6570\u4eba\u7684\u5174\u8da3\uff0c\u8fd9\u4e5f\u5305\u62ec\u4e86\u6211\u3002\u60f3\u901a\u8fc7\u8ba1\u7b97\u673a\u7a0b\u5e8f\u6c42\u89e3\u8be5\u95ee\u9898\uff0c\u4e8e\u662f\u82b1\u8d39\u4e86\u4e00\u4e0b\u5348\u7684\u65f6\u95f4\uff0c\u7ec8\u4e8e\u6210\u529f\u6c42\u89e3\u3002\u73b0\u5c06\u7a0b\u5e8f\u6e90\u7801\u548c\u601d\u8def\u5206\u4eab\u5982\u4e0b\uff01<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.xttblog.game; \npublic class Point { \n    private int col;\/\/ \u884c\u53f7 \n    private int row;\/\/ \u5217\u53f7 \n    private boolean flag;\/\/ \u771f\u4e3a\u672a\u8bbe\u7f6e\u3002 \n    private int value; \n    \/\/ \u6784\u9020\u70b9 \n    public Point(int col, int row, boolean flag, int value) { \n        super(); \n        this.col = col; \n        this.row = row; \n        this.flag = flag; \n        this.value = value; \n    } \n    public void changeFlag() { \n        flag = !flag; \n    } \n    public boolean getFlag() { \n        return flag; \n    } \n    public int getValue() { \n        return value; \n    } \n    public void setValue(int value) { \n        this.value = value; \n    } \n    public boolean canHere(Point[][] pArr) { \n        boolean cb = canCol(pArr); \n        boolean cr = canRow(pArr); \n        boolean cminiArr = canMiniArr(pArr); \n        return cb &amp;&amp; cr &amp;&amp; cminiArr; \n    } \n    \/\/\u5224\u65ad\u5728\u5c0f3*3\u683c\u5b50\u91cc\u662f\u5426\u6709\u76f8\u540c\u5143\u7d20 \n    private boolean canMiniArr(Point[][] pArr) { \n        int coltemp = this.col % 3; \n        int rowtemp = this.row % 3; \n        for (int i = this.col - coltemp; i &lt; col + (3 - coltemp); i++) { \n            for (int j = this.row - rowtemp; j &lt; row + (3 - rowtemp); j++) { \n                if(i == this.col &amp;&amp; j == this.row){ \n                    continue; \n                }else{               \n                    if(this.value == pArr[i][j].getValue()){ \n                        return false; \n                    }                \n                } \n            } \n        } \n        return true; \n    } \n    \/\/ \u5224\u65ad\u5217\u4e0a\u662f\u5426\u6709\u76f8\u540c\u5143\u7d20 \n    private boolean canRow(Point[][] pArr) { \n        for (int i = 0; i &lt; 9; i++) { \n            if (i == this.col) { \n                continue; \n            } else { \n                if (this.value == pArr[i][this.row].value) {\/\/ \u884c\u53d8\uff0c\u5217\u4e0d\u53d8 \n                    return false; \n                } \n            } \n        } \n        return true; \n    }\n    \/\/ \u5224\u65ad\u884c\u4e0a\u662f\u5426\u6709\u76f8\u540c\u5143\u7d20 \n    private boolean canCol(Point[][] pArr) { \n        for (int i = 0; i &lt; 9; i++) { \n            if (i == this.row) { \n                continue; \n            } else { \n                if (this.value == pArr[this.col][i].value) {\/\/ \u5217\u8fb9\uff0c\u884c\u4e0d\u53d8 \n                    return false; \n                } \n            } \n        } \n        return true; \n    } \n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u662f\u90e8\u5206\u89e3\u9898\u7684\u7b80\u5355\u51fd\u6570\uff0c\u4e3b\u7a0b\u5e8f\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\u6240\u793a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.xttblog.game; \nimport java.io.BufferedReader; \nimport java.io.IOException; \nimport java.io.InputStreamReader; \nimport java.util.ArrayList; \npublic class Number99 { \n    public static void main(String[] args) throws IOException{ \n        Point[][] numMat = new Point[9][9]; \n        ArrayList&lt;Point&gt; al = new ArrayList&lt;Point&gt;(); \n\n        initNumMat(numMat,al); \n\n        setNum(numMat,al); \n        printMat(numMat); \n    } \n\n    private static void setNum(Point[][] numMat,ArrayList&lt;Point&gt; al) { \n        int i = 0; \n        int j = 0; \n        do{ \n            if (numMat[i][j].getFlag()) { \n                for (int v = numMat[i][j].getValue()+1; v &lt;= 9; v++) {\/\/\u7ed9\u56de\u9000\u5230\u7684\u4f4d\u7f6e\u7684\u503c\u52a0\u4e00\u3002 \n                    numMat[i][j].setValue(v); \n                    if (numMat[i][j].canHere(numMat)) {\/\/\u6ee1\u8db3\u6761\u4ef6\uff0c\u4e0d\u51b2\u7a81\u3002 \n                        numMat[i][j].changeFlag();\/\/\u6539\u53d8\u6807\u8bb0\u4e3a\u5047\u3002\u8868\u793a\u5df2\u8bbe\u7f6e\u8fc7\u3002 \n                        break; \n                    }else{\/\/\u6ee1\u8db3\u4e0d\u6761\u4ef6\uff0c\u51b2\u7a81\u3002value\u503c\u81ea\u52a0\u4e00\u6b21 \n                    }    \n\n                    while(v == 9){\/\/\u5982\u679c1-9\u90fd\u4e0d\u80fd\u6ee1\u8db3\u8981\u6c42\uff0c\u5219\u5148\u5c06\u672c\u4f4d\u91cd\u7f6e\u4e3a0\uff0c\u5e76\u56de\u9000\u4e00\u683c,\u7ed9\u56de\u9000\u5230\u7684\u4f4d\u7f6e\u7684\u503c\u52a0\u4e00\uff08\u5f53\u56de\u9000\u4f4d\u7f6e\u7684\u503c\u4e0d\u4e3a9\u65f6,\u5e76\u4e14\u4fdd\u8bc1\u56de\u9000\u5230\u7684\u4f4d\u7f6e\u4e0d\u662f\u4e5d\u5bab\u683c\u539f\u672c\u7684\u70b9\uff09\u3002 \n                        numMat[i][j].setValue(0); \n                        j--; \n                        if(j==-1){ \n                            i--;j=8; \n                        } \n                        while(al.contains(numMat[i][j])){\/\/\u5982\u679c\u56de\u9000\u5230\u7684\u4f4d\u7f6e\u4e3a\u4e5d\u5bab\u683c\u672c\u6765\u7684\u70b9\u65f6\uff0c\u7ee7\u7eed\u56de\u9000\uff0c\u76f4\u5230\u4e0d\u662f\u672c\u8eab\u7684\u70b9\u65f6\u8df3\u51fawhile\u3002 \n                            j--; \n                            if(j==-1){ \n                                i--;j=8; \n                            } \n                        } \n                        numMat[i][j].changeFlag();\/\/\u5c06\u6807\u8bb0 \n                        v = numMat[i][j].getValue(); \n                    } \n                }            \n            } \n            j++; \n            if(j==9){ \n                j=0;i++;\/\/\u6b64\u5904i++ \u53ef\u80fd\u4f7fi\u81ea\u52a0\u4e3a9\uff0c\u6545\u4e0b\u9762\u9700\u8981i!=9\u5224\u65ad \n            } \n            if(i!=9){            \n                while(al.contains(numMat[i][j])){ \n                    j++; \n                    if(j==9){ \n                        j=0;i++; \n                    } \n                } \n            } \n        }while(i!=9); \n    } \n    public static void initNumMat(Point[][] numMat,ArrayList&lt;Point&gt; al) throws IOException { \n        for (int i = 0; i &lt; numMat.length; i++) { \n            for (int j = 0; j &lt; numMat[i].length; j++) { \n                numMat[i][j] = new Point(i, j, true, 0); \n            } \n        } \n        initNumMat2(numMat, al); \n\n    } \n    public static void initNumMat2(Point[][] numMat, ArrayList&lt;Point&gt; al) throws IOException { \n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); \n        String[] p = new String[3]; \n        String line=null; \n        System.out.println(\"\u8bf7\u6309\u683c\u5f0f\u8f93\u5165\u70b9\u4fe1\u606f\uff08i\u884c\u53f7, j\u5217\u53f7 v\u503c\uff09,\u8f93\u5165\u7ed3\u675f\u8f93\u5165over: i j v \"); \n        while((line = br.readLine())!=null){ \n            if(line.equals(\"over\")) \n                break; \n            p = line.trim().split(\" +\"); \n            numMat[Integer.parseInt(p[0])][Integer.parseInt(p[1])].setValue(Integer.parseInt(p[2])); \n            numMat[Integer.parseInt(p[0])][Integer.parseInt(p[1])].changeFlag(); \n            al.add(numMat[Integer.parseInt(p[0])][Integer.parseInt(p[1])]); \n        } \n    } \n    public static void printMat(Point[][] numMat) { \n        System.out.println(\"--------\u252c---------\u252c---------\u2510\"); \n        for (int i = 0; i &lt; numMat.length; i++) { \n            for (int j = 0; j &lt; numMat[i].length; j++) { \n                if ((j + 1) % 3 == 0) \n                    System.out.print(numMat[i][j].getValue() + \" | \"); \n                else \n                    System.out.print(numMat[i][j].getValue() + \"  \"); \n            } \n            if ((i + 1) % 3 == 0) \n                System.out.println(\"\\r\\n--------\u253c---------\u253c---------\u2524\"); \n            else \n                System.out.println(); \n        } \n    } \n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7a0b\u5e8f\u8fd0\u884c\u4e4b\u540e\uff0c\u53ef\u4ee5\u6309\u7167\u4e0b\u9762\u7684\u683c\u5f0f\u8f93\u5165\u5185\u5bb9\u3002\uff08i\u884c\u53f7, j\u5217\u53f7 v\u503c\uff09,\u8f93\u5165\u7ed3\u675f\u8f93\u5165over\u3002\u73b0\u5047\u8bbe\u8f93\u5165\u7684\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>i j v\n0 0 8\n1 2 3\n1 3 6\n2 1 7\n2 4 9\n2 6 2\n3 1 5\n3 5 7\n4 4 4\n4 5 5\n4 6 7\n5 3 1\n5 7 3\n6 2 1\n6 7 6\n6 8 8\n7 2 8\n7 3 5\n7 7 1\n8 1 9\n8 6 4\nover<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u7ec8\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u2014\u2014\u2013\u252c\u2014\u2014\u2014\u252c\u2014\u2014\u2014\u2510\n8  1  2 | 7  5  3 | 6  4  9 |\n9  4  3 | 6  8  2 | 1  7  5 |\n6  7  5 | 4  9  1 | 2  8  3 |\n\u2014\u2014\u2013\u253c\u2014\u2014\u2014\u253c\u2014\u2014\u2014\u2524\n1  5  4 | 2  3  7 | 8  9  6 |\n3  6  9 | 8  4  5 | 7  2  1 |\n2  8  7 | 1  6  9 | 5  3  4 |\n\u2014\u2014\u2013\u253c\u2014\u2014\u2014\u253c\u2014\u2014\u2014\u2524\n5  2  1 | 9  7  4 | 3  6  8 |\n4  3  8 | 5  2  6 | 9  1  7 |\n7  9  6 | 3  1  8 | 4  5  2 |\n\u2014\u2014\u2013\u253c\u2014\u2014\u2014\u253c\u2014\u2014\u2014\u2524<\/code><\/pre>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=4720\">\u7b80\u5355\u767e\u884cJava\u4ee3\u7801\u89e3\u4e16\u754c\u6700\u96be\u4e5d\u5bab\u683c<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u4e16\u754c\u6700\u96be\u4e5d\u5bab\u683c\u5230\u5e95\u6709\u591a\u96be\uff1f\u636e\u8bf4\uff0c\u5f88\u591a\u6570\u5b66\u5bb6\u90fd\u641e\u4e0d\u5b9a\uff01\u771f\u7684\u662f\u8fd9\u6837\u5417\uff1f\u4eca\u5929\u6211\u4eec\u4e00\u8d77\u6765\u4f7f\u7528 Java \u641e\u5b9a\u5b83\u3002 \u82ac\u5170 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[871,1610,685,172,75],"class_list":["post-4720","post","type-post","status-publish","format-standard","hentry","category-yyzt","tag-idea","tag-rete","tag-685","tag-172","tag-75"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4720","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4720"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4720\/revisions"}],"predecessor-version":[{"id":4721,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4720\/revisions\/4721"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}