• <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>
            alpc60 ACM/ICPC程序設計
            成長的路……源
            posts - 20,comments - 42,trackbacks - 0
             

            2676 Sudoku

             

            Source from http://acm.pku.edu.cn/JudgeOnline/problem?id=2676

            Sudoku中文名“數獨”游戲,游戲規則是在一個9×9的方格中填入199個數字,9×9的大方格又被劃分成了93×3的小方格,要求填入的這199個數字中,在每一行,每一列及每一個小方格中都不能重復出現。

            pku上,我暴搜的方法,將每個空格的位置幾下,然后用dfs往里填數,不符合條件的就回溯。方法如下:

            Source

             

            Problem: 2676 User: alpc60

            Memory: 80K Time: 1171MS

            Language: C++ Result: Accepted

             

            Source

            #include <stdio.h>

            #include <string.h>

             

            struct P

            {

                   int x,y,num;

            }point[100];

            int map[10][10],count;

            bool mr[10][10],mc[10][10],mm[10][10];

             

            int dfs(int n);

            int find(int x, int y);

             

            int main()

            {

                   int i,j,cases;

                   //freopen("2676.txt","r",stdin);

                   scanf("%d",&cases);

                   while(cases--)

                   {

                          count=0;

                          memset(mc,false,sizeof(mc));

                          memset(mr,false,sizeof(mr));

                          memset(mm,false,sizeof(mm));

                          memset(map,0,sizeof(map));

                          for(i=1; i<=9; i++)

                                 for(j=1; j<=9; j++)

                                 {

                                        scanf("%1d",&map[i][j]);

                                        if(map[i][j]==0)

                                        {

                                               point[count].x=i;

                                               point[count].y=j;

                                               point[count].num=0;

                                               count++;

                                        }

                                        else

                                        {

                                               mr[i][map[i][j]]=true;

                                               mc[j][map[i][j]]=true;

                                               mm[find(i,j)][map[i][j]]=true;

                                        }

                                 }

                          dfs(0);

                          //{

                                 for(i=0; i<count; i++)

                                        map[point[i].x][point[i].y]=point[i].num;

                                 for(i=1; i<=9; i++)

                                 {

                                        for(j=1; j<=9; j++)

                                        {

                                               printf("%d",map[i][j]);

                                        }

                                        printf("\n");

                                 }

                          //}

                   }

                   return 0;

            }

            int dfs(int n)

            {

                   int i,t;

                   if(n>=count)

                          return 1;

                   t=find(point[n].x,point[n].y);

                   for(i=1; i<=9; i++)

                   {

                          if(!mr[point[n].x][i] && !mc[point[n].y][i] && !mm[t][i])

                          {

                                 mr[point[n].x][i]=true;

                                 mc[point[n].y][i]=true;

                                 mm[t][i]=true;

                                 point[n].num=i;

                                 if(dfs(n+1))

                                        return 1;

                                 mr[point[n].x][i]=false;

                                 mc[point[n].y][i]=false;

                                 mm[t][i]=false;

                                 point[n].num=0;

                          }

                   }

                   return 0;

            }

            int find(int x, int y)

            {

                   int r,c;

                   r=x%3?(x/3+1):(x/3);

                   c=y%3?(y/3+1):(y/3);

                   return (r-1)*3+c;

            }

            posted on 2007-09-23 15:29 飛飛 閱讀(707) 評論(0)  編輯 收藏 引用 所屬分類: ACM/ICPC
            少妇人妻综合久久中文字幕| 亚洲成色999久久网站| 久久国产精品99久久久久久老狼| 久久久久久青草大香综合精品| 久久Av无码精品人妻系列| 色综合久久久久综合体桃花网| 久久精品免费一区二区| 国产69精品久久久久9999APGF| 久久久久久精品免费免费自慰| 久久久久久伊人高潮影院| 久久综合偷偷噜噜噜色| 久久91精品国产91| 精品久久久久香蕉网| 99精品久久精品一区二区| 久久99精品综合国产首页| 国产午夜精品理论片久久| 一本色道久久88综合日韩精品| 久久久久久伊人高潮影院| 久久99国产综合精品免费| 国产精品亚洲美女久久久| 午夜精品久久久久9999高清| 天天躁日日躁狠狠久久| 国产精品久久久久久久久鸭| 国产精品无码久久四虎| 国产成年无码久久久免费| 狠狠色丁香婷婷综合久久来| 国产成人综合久久精品尤物| 国产精品久久新婚兰兰| 久久综合九色综合97_久久久| 国产精品嫩草影院久久| 亚洲AV乱码久久精品蜜桃| 国产精品欧美亚洲韩国日本久久| 久久久91人妻无码精品蜜桃HD| 免费精品久久天干天干| 久久婷婷国产麻豆91天堂| 国产精品久久久久久久久久影院| 精品国产乱码久久久久久郑州公司 | 亚洲精品乱码久久久久久| 久久精品国产一区| 久久精品国产久精国产一老狼| 亚洲狠狠综合久久|