zoukankan      html  css  js  c++  java
  • AcWing每日一题(提高组)--数度简单版

    https://www.acwing.com/problem/content/1615/

    写出一个正确的dfs就可以了。

     1 #include<iostream>
     2 using namespace std;
     3 char s[9][9];
     4 bool row[9][10],col[9][10],cell[3][3][10];
     5 bool dfs(int x,int y){
     6     if(y==9) x++,y=0;
     7     if(x==9){
     8         for (int i=0;i<9;i++){
     9             for(int j=0;j<9;j++){
    10                 cout<<s[i][j];
    11             }
    12             cout<<endl;
    13         }
    14         return true;
    15     }
    16     if(s[x][y]!='.') return dfs(x,y+1);
    17     for(int i=1;i<=9;i++){
    18         if(!row[x][i]&&!col[y][i]&&!cell[x/3][y/3][i]){
    19             s[x][y]='0'+i;
    20             row[x][i]=col[y][i]=cell[x/3][y/3][i]=true;
    21             if(dfs(x,y+1))
    22                 return true;
    23             row[x][i]=col[y][i]=cell[x/3][y/3][i]=false;
    24             s[x][y]='.';
    25         }
    26     }
    27     return false;
    28 }
    29 int main(void){
    30     for(int i=0;i<9;i++){
    31         cin>>s[i];
    32     }
    33     for(int i=0;i<9;i++){
    34         for(int j=0;j<9;j++){
    35             if(s[i][j]>='0'&&s[i][j]<='9'){
    36                 int u=s[i][j]-'0';
    37                 row[i][u]=true;
    38                 col[j][u]=true;
    39                 cell[i/3][j/3][u]=true;
    40             }
    41         }
    42     }
    43     dfs(0,0);
    44     return 0;
    45 }
  • 相关阅读:
    python file op
    python write read
    Linux MD RAID 10
    bitmap.h
    1
    write 1 to block device
    tr '00' '377' < /dev/zero | dd of=/dev/$i bs=1024 count=1024000
    Superblock
    echo -e "33[41;36m something here 33[0m"
    May It Be
  • 原文地址:https://www.cnblogs.com/greenofyu/p/14396048.html
Copyright © 2011-2022 走看看