• <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
            久久天天躁狠狠躁夜夜躁2O2O| 欧美精品九九99久久在观看| 国产美女久久精品香蕉69| 99久久免费国产特黄| 久久亚洲电影| 日韩精品久久久久久| 久久精品国产清自在天天线 | 亚洲中文字幕久久精品无码喷水| 久久www免费人成看片| 久久99精品国产麻豆宅宅| 怡红院日本一道日本久久| 亚洲精品无码久久久久AV麻豆| 久久久久久亚洲精品成人| 久久精品二区| 久久九九亚洲精品| 99久久人妻无码精品系列蜜桃| 亚洲七七久久精品中文国产| 色综合久久88色综合天天| 久久人人爽人人爽人人片av高请| 午夜福利91久久福利| 国产精品久久久久久久午夜片 | 久久精品国产免费观看| 久久嫩草影院免费看夜色| 久久精品亚洲男人的天堂| 亚洲精品高清久久| 国产精品视频久久久| 国产成人久久精品激情| 亚洲AV无码1区2区久久| 东方aⅴ免费观看久久av| 麻豆久久| 久久久久久久97| 久久人人爽人人爽人人片av麻烦 | 久久这里只有精品视频99| 久久人人爽人爽人人爽av| 国产精品熟女福利久久AV| 国产亚洲精午夜久久久久久| 精品一久久香蕉国产线看播放 | 亚洲va久久久噜噜噜久久男同 | 色欲av伊人久久大香线蕉影院 | 久久免费精品视频| 久久精品国产亚洲网站|