2015ccpc——H
来源:互联网 发布:尚观云计算课程 编辑:程序博客网 时间:2024/06/03 21:58
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 a 4×44×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×22×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!!!
Input
The first line of the input gives the number of test cases, T(1≤T≤100)T(1≤T≤100). TT 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.
Output
For each test case, output one line containing Case #x:, where xx is the test case number (starting from 1). Then output 4 lines with 4 characters each. indicate the recovered board.
Sample Input
3
****
2341
4123
3214
*243
*312
*421
*134
*41*
**3*
2*41
4*2*
Sample Output
Case #1:
1432
2341
4123
3214
Case #2:
1243
4312
3421
2134
Case #3:
3412
1234
2341
Actually, Yi Sima was playing it different. First of all, he tried to generate a 4×44×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×22×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!!!
Input
The first line of the input gives the number of test cases, T(1≤T≤100)T(1≤T≤100). TT 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.
Output
For each test case, output one line containing Case #x:, where xx is the test case number (starting from 1). Then output 4 lines with 4 characters each. indicate the recovered board.
Sample Input
3
****
2341
4123
3214
*243
*312
*421
*134
*41*
**3*
2*41
4*2*
Sample Output
Case #1:
1432
2341
4123
3214
Case #2:
1243
4312
3421
2134
Case #3:
3412
1234
2341
4123
题意:每一行、每一列、还有四个小的2*2的小矩阵中用1,2,3,4去填写,不能重复
解题思路:直接dfs判断就好了。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;char maze[5][5];int judge(int x,int y,char c){ for(int i=0;i<4;i++)//判断行、列 { if(maze[x][i]==c||maze[i][y]==c) return 0; } if(x/2==0&&y/2==0)//判断左上 { if(maze[0][0]==c||maze[0][1]==c||maze[1][0]==c||maze[1][1]==c) return 0; } else if(x/2==0&&y/2==1)//判断右上 { if(maze[0][2]==c||maze[0][3]==c||maze[1][2]==c||maze[1][3]==c) return 0; } else if(x/2==1&&y/2==0)//判断左下 { if(maze[2][0]==c||maze[2][1]==c||maze[3][0]==c||maze[3][1]==c) return 0; } else if(x/2==1&&y/2==1)//判断右下 { if(maze[2][2]==c||maze[2][3]==c||maze[3][2]==c||maze[3][3]==c) return 0; } return 1;}void dfs(int x,int y){ if(x==4) { for(int i=0;i<4;i++) { printf("%s\n",maze[i]); } return ; } else { if(maze[x][y]!='*') { if(y==3)//该行的最后一列 { dfs(x+1,0); } else dfs(x,y+1); } else { for(int i=1;i<=4;i++) { if(judge(x,y,i+'0'))//每个数去尝试,可以就放 { maze[x][y]=i+'0'; if(y==3) dfs(x+1,0); else dfs(x,y+1); maze[x][y]='*';//回溯 } } } }}int main(){ int t,cas=1; scanf("%d",&t); while(t--) { for(int i=0;i<4;i++) scanf("%s",maze[i]); printf("Case #%d:\n",cas++); dfs(0,0); } return 0;}
阅读全文
0 0
- 2015ccpc——H
- 2015 CCPC H题 【DFS】
- 2015ccpc——G
- 2015CCPC南阳场 H - Sudoku
- H - Sudoku【ccpc dfs】
- ccpc东北四——重现赛
- 【HDU5547 2015 CCPC 南阳国赛H】【DFS】Sudoku 4x4棋盘的填充
- 2017 江苏省赛(湘潭市ccpc)H题
- 2017 ccpc 湘潭邀请赛 H highway
- ZOJ 3988(ccpc秦皇岛H)
- CCPC.2017秦皇岛站 H-prime set
- H——H
- 2015 ccpc G题解
- CCPC 2015 A题
- 2015 CCPC D题
- 2015 CCPC Ancient Go
- 2015 ICPC && CCPC - 小记
- 2015南阳CCPC Hdu5547
- 数位DP——HDU6148 Valley Number
- Data Structures and algorithm analysis—1.3. A Brief Introduction to Recursion(数据结构—1.3 递归的简介)(之二)
- Kettle安装和配置
- 扫描--不是网传雷达
- 机器人操作系统ros ———一个月的学习历程
- 2015ccpc——H
- 你能获得的数据量越大,你能挖掘到的价值就越多。
- 初写定时压缩日志任务总结
- android 自带日历控件datePicker
- 模拟实现memcpy,memmove,atoi,itoa
- MapReduce 如何输出多个文件:MultipleOutputs 运用可行
- 序列化form表单元素为对象
- Java编程思想之数组
- Vs2008制作WinCE Cab安装包