• <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
            久久精品成人免费国产片小草| 日韩精品久久久久久久电影| 国产精品美女久久久m| 久久精品国产亚洲AV无码偷窥 | 无码人妻久久一区二区三区| 熟妇人妻久久中文字幕| 欧美综合天天夜夜久久| 一级a性色生活片久久无| 久久久久亚洲av无码专区喷水| 麻豆精品久久精品色综合| 中文字幕亚洲综合久久菠萝蜜| 久久ZYZ资源站无码中文动漫| 欧美精品福利视频一区二区三区久久久精品 | 1000部精品久久久久久久久| 久久精品国产亚洲7777| 久久人爽人人爽人人片AV| 久久精品国产一区二区 | 色综合久久久久| 亚洲乱码中文字幕久久孕妇黑人| 99久久精品免费看国产免费| 无码伊人66久久大杳蕉网站谷歌| 日批日出水久久亚洲精品tv| 国产精品一久久香蕉产线看| 久久久国产精华液| 久久综合色之久久综合| 久久国产精品免费一区| 国产精品久久久久jk制服| 中文字幕久久精品| 色天使久久综合网天天| 色综合色天天久久婷婷基地| 国内精品久久久久影院一蜜桃| 无码人妻少妇久久中文字幕蜜桃| 香港aa三级久久三级老师2021国产三级精品三级在 | 久久精品国产男包| 久久这里的只有是精品23| 久久人人超碰精品CAOPOREN| 精品国产91久久久久久久a| 99久久精品免费看国产免费| 99久久综合狠狠综合久久| 亚洲国产成人久久综合一 | 久久国产精品99久久久久久老狼|