• <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)

            我參與的團隊

            搜索

            •  

            積分與排名

            • 積分 - 326969
            • 排名 - 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 閱讀(313) 評論(0)  編輯 收藏 引用 所屬分類: Algorithm
            久久―日本道色综合久久| 亚洲中文久久精品无码ww16| 亚洲国产精品无码久久| 亚洲综合精品香蕉久久网| 久久大香萑太香蕉av| 囯产精品久久久久久久久蜜桃| 日韩av无码久久精品免费| 久久国产精品波多野结衣AV| 狠狠色丁香久久婷婷综合蜜芽五月| 久久久久亚洲av无码专区| 欧美性大战久久久久久 | 久久免费的精品国产V∧| 国产成人香蕉久久久久| 一本色综合网久久| 亚洲精品视频久久久| 99久久精品免费国产大片| 熟妇人妻久久中文字幕| 亚洲国产日韩综合久久精品| 成人精品一区二区久久 | 99国内精品久久久久久久 | 久久本道久久综合伊人| 精品九九久久国内精品| 亚洲色大成网站WWW久久九九| 久久这里只有精品视频99| 国产精品激情综合久久| 国产精品久久久久影院色| 奇米影视7777久久精品| 少妇久久久久久被弄高潮| 一本色道久久综合| 久久久久久久综合狠狠综合| 婷婷久久综合| 久久精品青青草原伊人| 欧美久久一级内射wwwwww.| 国产精久久一区二区三区| 久久久久久狠狠丁香| 岛国搬运www久久| 韩国三级中文字幕hd久久精品| 国产精品激情综合久久| 色偷偷91久久综合噜噜噜噜| 久久婷婷是五月综合色狠狠| 亚洲乱码中文字幕久久孕妇黑人|