• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            為生存而奔跑

               :: 首頁 :: 聯系 :: 聚合  :: 管理
              271 Posts :: 0 Stories :: 58 Comments :: 0 Trackbacks

            留言簿(5)

            我參與的團隊

            搜索

            •  

            積分與排名

            • 積分 - 328433
            • 排名 - 74

            最新評論

            閱讀排行榜

            評論排行榜

            http://acm.pku.edu.cn/JudgeOnline/problem?id=2676
            #include
            <iostream>
            #include
            <algorithm>
            #include
            <string>
            #include
            <vector>
            #include
            <cmath>
            #include
            <map>
            using namespace std;
            int a[10][10];
            bool row[10][10],col[10][10],square[10][10];
            struct node
            {
                
            int x,y;
            }q[
            81];
            int top;
            int getsquare(const int & x,const int & y)
            {
                
            return x/3*3+y/3;
            }
            bool check(const int & x,const int & y,const int & k)
            {
                
            return ( !row[x][k] && !col[y][k] && !square[getsquare(x,y)][k] );
            }
            bool dfs()
            {
                node tmp;
                
            if(top!=0)
                {
                    tmp
            =q[--top];
                    
            for(int i=1;i<10;i++)
                    {
                        
            if(check(tmp.x,tmp.y,i))
                        {
                            row[tmp.x][i]
            =1;
                            col[tmp.y][i]
            =1;
                            square[getsquare(tmp.x,tmp.y)][i]
            =1;
                            
            if(dfs())
                            {
                                a[tmp.x][tmp.y]
            =i;
                                
            return 1;
                            }
                            
            else
                            {
                                row[tmp.x][i]
            =0;
                                col[tmp.y][i]
            =0;
                                square[getsquare(tmp.x,tmp.y)][i]
            =0;
                            }
                        }
                    }
                    q[top
            ++]=tmp;
                    
            return 0;
                }
                
            return 1;
            }
            int main()
            {
                
            int t;
                
            char s[10];
                scanf(
            "%d",&t);
                getchar();
                
            while(t--)
                {
                    memset(col,
            false,sizeof(col));
                    memset(row,
            false,sizeof(row));
                    memset(square,
            false,sizeof(square));
                    top
            =0;
                    
            for(int i=0;i<9;i++)
                    {
                        gets(s);
                        
            for(int j=0;j<9;j++)
                        {
                            a[i][j]
            =s[j]-'0';
                            
            if(a[i][j]!=0)
                            {
                                row[i][a[i][j]]
            =1;
                                col[j][a[i][j]]
            =1;
                                square[getsquare(i,j)][a[i][j]]
            =1;
                            }
                            
            else
                            {
                                q[top].x
            =i,q[top].y=j;
                                top
            ++;
                            }
                        }
                    }
                    dfs();
                    
            for(int i=0;i<9;i++)
                    {
                        
            for(int j=0;j<9;j++)
                            printf(
            "%d",a[i][j]);
                        printf(
            "\n");
                    }
                }
            }

            posted on 2009-10-05 20:52 baby-fly 閱讀(318) 評論(0)  編輯 收藏 引用 所屬分類: Algorithm
            A级毛片无码久久精品免费| 国产成人精品免费久久久久| 品成人欧美大片久久国产欧美 | 久久久久夜夜夜精品国产| 久久久国产精品网站| 久久综合九色综合欧美就去吻| 一本一道久久综合狠狠老| 999久久久免费国产精品播放| 亚洲一区精品伊人久久伊人| 久久精品国产99久久久| 婷婷久久综合| 精品久久国产一区二区三区香蕉| 久久久www免费人成精品| 久久亚洲综合色一区二区三区| 久久精品国产欧美日韩99热| 99精品久久久久中文字幕| 久久精品国产亚洲AV不卡| 99久久国产热无码精品免费久久久久| 国内高清久久久久久| 久久无码人妻精品一区二区三区 | 久久这里只有精品首页| 人人妻久久人人澡人人爽人人精品| 一级做a爰片久久毛片人呢| 久久婷婷五月综合色高清| 久久这里的只有是精品23| 久久国产免费直播| 日本三级久久网| 久久婷婷久久一区二区三区| 久久99国内精品自在现线| 亚洲AV无码久久精品蜜桃| 欧美日韩精品久久久久| 伊人色综合久久天天网| 亚洲人AV永久一区二区三区久久| 国产精品免费久久| 久久精品国产黑森林| 久久国产乱子伦精品免费午夜| 久久国产成人| 看全色黄大色大片免费久久久| 欧美精品丝袜久久久中文字幕 | 久久国产成人精品麻豆| 1000部精品久久久久久久久|