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

            我參與的團隊

            搜索

            •  

            積分與排名

            • 積分 - 326992
            • 排名 - 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
            99久久香蕉国产线看观香| 四虎国产精品免费久久5151| 久久伊人精品一区二区三区| 一本色道久久综合亚洲精品| 国内精品久久久久影院免费| 久久精品一区二区影院| 久久久久人妻精品一区二区三区 | 97久久香蕉国产线看观看| 91精品免费久久久久久久久| 久久久无码精品亚洲日韩蜜臀浪潮| 99久久成人国产精品免费 | 亚洲精品乱码久久久久久按摩| 久久99国产精品99久久| 一本久久知道综合久久| 久久国产美女免费观看精品| 精品久久久久久久无码| 武侠古典久久婷婷狼人伊人| 热久久这里只有精品| 国产精品9999久久久久| 成人久久免费网站| 欧美激情精品久久久久久| 亚洲综合婷婷久久| 99久久精品国内| 久久国产精品成人片免费| 国产成人精品综合久久久| 久久99精品久久久久久齐齐| 久久久国产精品福利免费| 国产情侣久久久久aⅴ免费| 亚洲AV日韩AV永久无码久久| 久久频这里精品99香蕉久| 日本亚洲色大成网站WWW久久| 中文字幕成人精品久久不卡| 久久99中文字幕久久| AAA级久久久精品无码片| 久久久亚洲欧洲日产国码二区| 综合久久国产九一剧情麻豆| 久久免费看黄a级毛片| 久久久久波多野结衣高潮| 久久婷婷是五月综合色狠狠| 久久久午夜精品| 久久狠狠爱亚洲综合影院|