设为首页 加入收藏

TOP

POJ 2918 Tudoku [搜索]
2015-07-24 05:50:35 来源: 作者: 【 】 浏览:4
Tags:POJ 2918 Tudoku 搜索

和POJ2676一样哈,,,

原谅我水题目数 = =!。。。

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       using namespace std; int map[10][10]; char tmp[10][10]; bool row[10][10]; bool col[10][10]; bool grid[10][10]; bool DFS(int x,int y) { int here=3*((x-1)/3)+(y-1)/3+1; if(x==10) return true; if(map[x][y]) { bool flag; return y==9?flag=DFS(x+1,1):flag=DFS(x,y+1); } else { for(int num=1;num<=9;num++) { if(!row[x][num]&&!col[y][num]&&!grid[here][num]) { map[x][y]=num; row[x][num]=true; col[y][num]=true; grid[here][num]=true; bool flag; y==9?flag=DFS(x+1,1):flag=DFS(x,y+1); if(flag) return true; else { map[x][y]=0; row[x][num]=false; col[y][num]=false; grid[here][num]=false; } } } } return false; } int main() { //freopen("/home/rainto96/in.txt","r",stdin); int test; cin>>test; for(int times=1;times<=test;times++) { memset(map,0,sizeof(map)); memset(tmp,0,sizeof(tmp)); memset(grid,0,sizeof(grid)); memset(col,0,sizeof(col)); memset(row,0,sizeof(row)); for(int i=1;i<=9;i++) { for(int j=1;j<=9;j++) { cin>>tmp[i][j]; int here=3*((i-1)/3)+(j-1)/3+1; map[i][j]=tmp[i][j]-'0'; if(map[i][j]) { row[i][map[i][j]]=true; col[j][map[i][j]]=true; grid[here][map[i][j]]=true; } } } DFS(1,1); cout<<"Scenario #"<
      
       

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU 1542 Atlantis (线段树求矩.. 下一篇ajax――dom基础

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: