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

            我參與的團隊

            搜索

            •  

            積分與排名

            • 積分 - 328875
            • 排名 - 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 閱讀(319) 評論(0)  編輯 收藏 引用 所屬分類: Algorithm
            国产99久久久国产精免费| 欧美久久天天综合香蕉伊| 国产三级久久久精品麻豆三级 | 国产亚洲精品久久久久秋霞| 精品久久久久久无码专区 | 老男人久久青草av高清| 久久久久久九九99精品| 久久久久国色AV免费观看| 国色天香久久久久久久小说| 久久99精品免费一区二区| 久久婷婷国产综合精品| 久久久精品久久久久影院| 久久99毛片免费观看不卡 | 午夜视频久久久久一区| 国产精品一区二区久久| 国内精品九九久久精品| 亚洲精品99久久久久中文字幕| 国产成人久久精品区一区二区| 伊人久久大香线蕉成人| 久久精品国产一区二区电影| 国产精品欧美久久久天天影视| 欧美日韩精品久久免费| 久久久久亚洲精品男人的天堂| 久久精品国产精品亚洲毛片| 亚洲熟妇无码另类久久久| 思思久久99热只有频精品66| 婷婷久久综合九色综合绿巨人| 久久精品亚洲福利| 久久综合狠狠综合久久激情 | 欧美日韩精品久久久久| 久久久无码精品午夜| 久久精品国产一区二区三区| 久久免费大片| 性做久久久久久免费观看| 日韩中文久久| 久久精品国产AV一区二区三区| 久久精品国产色蜜蜜麻豆| 久久狠狠高潮亚洲精品| 国产一区二区三区久久| 亚洲国产精品婷婷久久| 久久99精品久久久久久秒播|