记住开数组的坑
来源:互联网 发布:如何安装越狱软件 编辑:程序博客网 时间:2024/06/06 10:16
Sudoku
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2217 Accepted Submission(s): 752
Problem Description
Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself. It looks like the modern Sudoku, but smaller.
Actually, Yi Sima was playing it different. First of all, he tried to generate a4×4 board with every row contains 1 to 4, every column contains 1 to 4. Also he made sure that if we cut the board into four 2×2 pieces, every piece contains 1 to 4.
Then, he removed several numbers from the board and gave it to another guy to recover it. As other counselors are not as smart as Yi Sima, Yi Sima always made sure that the board only has one way to recover.
Actually, you are seeing this because you've passed through to the Three-Kingdom Age. You can recover the board to make Yi Sima happy and be promoted. Go and do it!!!
Actually, Yi Sima was playing it different. First of all, he tried to generate a
Then, he removed several numbers from the board and gave it to another guy to recover it. As other counselors are not as smart as Yi Sima, Yi Sima always made sure that the board only has one way to recover.
Actually, you are seeing this because you've passed through to the Three-Kingdom Age. You can recover the board to make Yi Sima happy and be promoted. Go and do it!!!
Input
The first line of the input gives the number of test cases, T(1≤T≤100) . T test cases follow. Each test case starts with an empty line followed by 4 lines. Each line consist of 4 characters. Each character represents the number in the corresponding cell (one of '1', '2', '3', '4'). '*' represents that number was removed by Yi Sima.
It's guaranteed that there will be exactly one way to recover the board.
It's guaranteed that there will be exactly one way to recover the board.
Output
For each test case, output one line containing Case #x:, where x is the test case number (starting from 1). Then output 4 lines with 4 characters each. indicate the recovered board.
Sample Input
3****234141233214*243*312*421*134*41***3*2*414*2*
Sample Output
Case #1:1432234141233214Case #2:1243431234212134Case #3:3412123423414123
Source
The 2015 China Collegiate Programming Contest
#include <iostream>#include<stdio.h>#include<cstring>using namespace std;char maap[5][5];//这里maap[10001][10001]绝对不行int vis[11][11][11];int flagg;void dfs(int a,int b){ // cout<<"ofdsofdsofds"<<endl; for(int i=0; i<4; i++) { if(maap[a][i]!='*') { vis[a][b][maap[a][i]-'0']=1; } } for(int i=0; i<4; i++) { if(maap[i][b]!='*') { vis[a][b][maap[i][b]-'0']=1; } } if(a==0) { if(b==0) { if(maap[a+1][b+1]!='*') { vis[a][b][maap[a+1][b+1]-'0']=1; } } if(b==1) { if(maap[1][0]!='*') { vis[a][b][maap[1][0]-'0']=1; } } if(b==2) { if(maap[1][3]!='*') { vis[a][b][maap[1][3]-'0']=1; } } if(b==3) { if(maap[1][2]!='*') { vis[a][b][maap[1][2]-'0']=1; } } } if(a==1) { if(b==0) { if(maap[0][1]!='*') { vis[a][b][maap[0][1]-'*']=1; } } if(b==1) { if(maap[0][0]!='*') { vis[a][b][maap[0][0]-'*']=1; } } if(b==2) { if(maap[0][3]!='*') { vis[a][b][maap[0][3]-'0']=1; } } if(b==3) { if(maap[0][2]!='*') { vis[a][b][maap[0][2]-'0']=1; } } } if(a==2) { if(b==0) { if(maap[3][1]!='*') { vis[a][b][maap[3][1]-'0']=1; } } if(b==1) { if(maap[3][0]!='*') { vis[a][b][maap[3][0]-'0']=1; } } if(b==2) { if(maap[3][3]!='*') { vis[a][b][maap[3][3]-'0']=1; } } if(b==3) { if(maap[3][2]!='*') { vis[a][b][maap[3][2]-'0']=1; } } } if(a==3) { if(b==0) { if(maap[2][1]!='*') { vis[a][b][maap[2][1]-'0']=1; } } if(b==1) { if(maap[2][0]!='*') { vis[a][b][maap[2][0]-'0']=1; } } if(b==2) { if(maap[2][3]!='*') { vis[a][b][maap[2][3]-'0']=1; } } if(b==3) { if(maap[2][2]!='*') { vis[a][b][maap[2][2]-'0']=1; } } }}bool juge(int a,int b,int k){ // cout<<"ofdsofdsofds"<<endl; for(int i=0; i<4; i++) { if(maap[a][i]!='*') { if(maap[a][i]==k+'0') { return false; } } } for(int i=0; i<4; i++) { if(maap[i][b]!='*') { if(maap[i][b]==k+'0') { return false; } } } if(a==0) { if(b==0) { if(maap[a+1][b+1]!='*') { if(maap[a+1][b+1]==k+'0') { return false; } } } if(b==1) { if(maap[1][0]!='*') { if(maap[1][0]==k+'0') { return false; } } } if(b==2) { if(maap[1][3]!='*') { if(maap[1][3]==k+'0') { return false; } } } if(b==3) { if(maap[1][2]!='*') { if(maap[1][2]==k+'0') { return false; } } } } if(a==1) { if(b==0) { if(maap[0][1]!='*') { if(maap[0][1]==k+'0') { return false; } } } if(b==1) { if(maap[0][0]!='*') { if(maap[0][0]==k+'0') { return false; } } } if(b==2) { if(maap[0][3]!='*') { if(maap[0][3]==k+'0') { return false; } } } if(b==3) { if(maap[0][2]!='*') { if(maap[0][2]==k+'0') { return false; } } } } if(a==2) { if(b==0) { if(maap[3][1]!='*') { if(maap[3][1]==k+'0') return false; } } if(b==1) { if(maap[3][0]!='*') { if(maap[3][0]==k+'0') { return false; } } } if(b==2) { if(maap[3][3]!='*') { if(maap[3][3]==k+'0') { return false; } } } if(b==3) { if(maap[3][2]!='*') { if(maap[3][2]==k+'0') { return false; } } } } if(a==3) { if(b==0) { if(maap[2][1]!='*') { if(maap[2][1]==k+'0') { return false; } } } if(b==1) { if(maap[2][0]!='*') { if(maap[2][0]==k+'0') { return false; } } } if(b==2) { if(maap[2][3]!='*') { if(maap[2][3]==k+'0') { return false; } } } if(b==3) { if(maap[2][2]!='*') { if(maap[2][2]==k+'0') { return false; } } } } return true;}int suan(int a1,int b1,int k){ for(int i=0;i<4;i++) { if(maap[i][b1]!='*') { if(maap[i][b1]-'0'==k) return 0; } } for(int i=0;i<4;i++) { if(maap[a1][i]!='*') { if(maap[a1][i]-'0'==k) { return 0; } } } if(a1>=0&&a1<=1) { if(b1>=0&&b1<=1) { for(int i=0;i<=1;i++) { for(int j=0;j<=1;j++) { if(maap[i][j]-'0'==k) { return 0; } } } } } else { if(b1>=0&&b1<=1) { for(int i=2;i<=3;i++) { for(int j=0;j<=1;j++) { if(maap[i][j]-'0'==k) { return 0; } } } } else { for(int i=2;i<=3;i++) { for(int j=2;j<=3;j++) { if(maap[i][j]-'0'==k) { return 0; } } } } } return 1;}void dfs1(int i,int j){ if(j==4) { //if(i+1) dfs1(i+1,0); } if(i==4) { flagg=1; //if(j+1<4) //dfs(i,j+1); return; } else { if(maap[i][j]=='*') { for(int k=1;k<=4;k++) { if(juge(i,j,k)) { maap[i][j]=k+'0'; dfs1(i,j+1); if(flagg==0) { maap[i][j]='*'; } } } } else { dfs1(i,j+1); } }}int main(){ int t,T=1; scanf("%d",&t); while(t--) { for(int i=0; i<4; i++) { scanf("%s",maap[i]); } int flag=0; /* for(int i=0; i<4; i++) { for(int j=0; j<4; j++) { if(maap[i][j]=='*') { memset(vis,0,sizeof(vis)); dfs(i,j); int num=0; int poi; for(int p=1; p<=4; p++) { if(vis[i][j][p]==0) { num++; poi=p; } } if(num==1) { maap[i][j]=poi+'0'; } else { flag=1; } } } } if(flag)*/ // { flagg=0; dfs1(0,0); // } printf("Case #%d:\n",T++); for(int i=0; i<4; i++) { printf("%s\n",maap[i]); } } return 0;}
0 0
- 记住开数组的坑
- 记住该记住的
- 记住该记住的
- JS/PHP中,数组与字符串的转换,这次总算是记住了
- 应该记住的事件
- 我们应该记住的
- 一定要记住的
- 应该记住的事件
- 值得记住的一天!!!
- 记住糟糕的过去
- 记住糟糕的过去
- 记住糟糕的过去
- 记住糟糕的过去
- 记住糟糕的过去
- 记住糟糕的过去
- 记住糟糕的过去
- 记住糟糕的过去
- 记住糟糕的过去
- iOS开发--- WKWebView导致Controller不调用dealloc
- 利用windows的性能监视器测试存储性能
- Identity Mappings in Deep Residual Networks(译)
- Spring Bean的生命周期监听
- CentOS6.8服务器LAMP环境搭建(二) 使用cmake安装MySQL5.7.18
- 记住开数组的坑
- 将原生u-boot-2016.01版u-boot移植到友善之臂nanopi M3开发板
- 新人程序员如何脱颖而出
- Windows平台安装Qt5.8
- 批处理技巧 批处理获取上一条命令的执行结果
- sublime 怎样设置识别语言?(txt文本设置固定编程语言高亮)
- 理解进程和线程
- lua math库
- c#只启动一个软件并将其置于最前