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

            我參與的團隊

            搜索

            •  

            積分與排名

            • 積分 - 330224
            • 排名 - 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 閱讀(323) 評論(0)  編輯 收藏 引用 所屬分類: Algorithm
            欧美精品福利视频一区二区三区久久久精品 | 曰曰摸天天摸人人看久久久| 国产69精品久久久久99| 欧美午夜A∨大片久久 | 午夜精品久久久久久99热| 久久精品国产亚洲综合色| 久久综合亚洲色HEZYO国产| 中文字幕日本人妻久久久免费 | 久久精品国产亚洲av麻豆小说 | 东方aⅴ免费观看久久av| 999久久久无码国产精品| 久久综合久久鬼色| 国产精品视频久久| 亚洲国产精品无码久久| 久久久久一本毛久久久| 久久午夜电影网| 精品久久人妻av中文字幕| 久久国内免费视频| 久久国产V一级毛多内射| 国产综合久久久久久鬼色| 精品人妻伦九区久久AAA片69| 久久久久久国产a免费观看不卡 | 久久精品国产亚洲AV高清热| 久久亚洲精品国产亚洲老地址| 久久青青国产| 久久国产成人精品国产成人亚洲| 欧美精品一区二区精品久久| 欧美一区二区三区久久综合| 亚洲午夜久久久影院伊人| 久久久久久久久久久精品尤物| 免费久久人人爽人人爽av| 亚洲成av人片不卡无码久久| 亚洲精品久久久www| 久久青青草视频| 精品多毛少妇人妻AV免费久久 | 亚洲精品WWW久久久久久| 伊人热人久久中文字幕| 国内精品久久久久久麻豆| 久久国产精品免费| 亚洲午夜精品久久久久久app| 欧洲性大片xxxxx久久久|