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

            我參與的團隊

            搜索

            •  

            積分與排名

            • 積分 - 328415
            • 排名 - 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
            久久97精品久久久久久久不卡| 久久最近最新中文字幕大全| 久久播电影网| yy6080久久| 狠狠色婷婷综合天天久久丁香| 久久国产精品二国产精品| 亚洲国产成人久久笫一页| 久久精品黄AA片一区二区三区| 久久久黄片| 久久噜噜电影你懂的| 麻豆精品久久久久久久99蜜桃| 国产精品久久久福利| 一级做a爰片久久毛片免费陪| 欧美牲交A欧牲交aⅴ久久| 国产日韩久久久精品影院首页| 国产成人精品久久| 久久免费视频一区| 亚洲午夜久久久精品影院| 18岁日韩内射颜射午夜久久成人| 国产午夜精品理论片久久影视| 要久久爱在线免费观看| 国产精品VIDEOSSEX久久发布| 国产aⅴ激情无码久久| 色综合合久久天天给综看| 99久久综合狠狠综合久久| 精品综合久久久久久888蜜芽| 成人综合久久精品色婷婷| 一级做a爰片久久毛片看看| 久久午夜福利电影| 久久精品国产亚洲5555| 99久久精品免费| 精品视频久久久久| 久久人人爽人人澡人人高潮AV| a级毛片无码兔费真人久久| 99久久人人爽亚洲精品美女| 午夜不卡888久久| 国产精品99久久精品爆乳| 91性高湖久久久久| 老司机午夜网站国内精品久久久久久久久| 99久久精品国产毛片| 久久久久久亚洲精品无码|