H - Sudoku

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 a 4×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!!!

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.

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

****
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 题意:给你4*4的图,数独游戏,4个2*2的块独立,每行每列独立
题解:暴力
///
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a))
#define TS printf("111111\n")
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--)
#define READ(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define inf 100000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//****************************************
#define maxn 5
bool flag;
int ans=;
char mp[maxn][maxn];
bool test()
{
if((mp[][]-'')*(mp[][]-'')*(mp[][]-'')*(mp[][]-'')!=)return ;
//if((mp[0][2]+mp[0][3]+mp[1][2]+mp[1][3]-'0'-'0'-'0'-'0')!=10)return 0;
if((mp[][]-'')*(mp[][]-'')*(mp[][]-'')*(mp[][]-'')!=)return ;
// if((mp[2][0]+mp[2][1]+mp[3][0]+mp[3][1]-'0'-'0'-'0'-'0')!=10)return 0; if((mp[][]-'')*(mp[][]-'')*(mp[][]-'')*(mp[][]-'')!=)return ;
// if((mp[2][2]+mp[2][3]+mp[3][2]+mp[3][3]-'0'-'0'-'0'-'0')!=10)return 0; if((mp[][]-'')*(mp[][]-'')*(mp[][]-'')*(mp[][]-'')!=)return ;
return ;
}
void dfs(int x,int y,int t){
if(t==ans){
// cout<<1<<endl;
if(test()){
for(int i=;i<;i++){
for(int j=;j<;j++){
printf("%c",mp[i][j]);
}
cout<<endl;
flag=;
}
}
return ;
} if(flag)return ; if(mp[x][y] == '*'){
for(int k=;k<=;k++){
int flags=;
for(int i=;i<;i++){if(y!=i&&mp[x][i]==k+'')flags=;}
for(int i=;i<;i++){if(x!=i&&mp[i][y]==k+'')flags=;}
if(flags)continue; mp[x][y]=k+'';
if(y==){dfs(x+,,t+);}
else {dfs(x,y+,t+);}
if(flag)return ;
mp[x][y]='*';
}
}
else {
if(y==)
dfs(x+,,t);
else dfs(x,y+,t);
} }
int main(){
int T=read();
int oo=;
while(T--){
ans=;flag=;
for(int i=;i<;i++){
scanf("%s",mp[i]);
for(int j=;j<;j++){
if(mp[i][j]=='*')ans++;
}
}
printf("Case #%d:\n",oo++);
dfs(,,);
}
return ;
}

代码

2015南阳CCPC H - Sudoku 数独的更多相关文章

  1. 2015南阳CCPC H - Sudoku 暴力

    H - Sudoku Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Yi Sima was one of the best cou ...

  2. 2015南阳CCPC E - Ba Gua Zhen 高斯消元 xor最大

    Ba Gua Zhen Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description During the Three-Kingdom perio ...

  3. 2015南阳CCPC F - The Battle of Guandu 多源多汇最短路

    The Battle of Guandu Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description In the year of 200, t ...

  4. 2015南阳CCPC L - Huatuo's Medicine 水题

    L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous ...

  5. 2015南阳CCPC G - Ancient Go 暴力

    G - Ancient Go Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Yu Zhou likes to play Go wi ...

  6. 2015南阳CCPC D - Pick The Sticks dp

    D - Pick The Sticks Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description The story happened lon ...

  7. 2015南阳CCPC A - Secrete Master Plan 水题

    D. Duff in Beach Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Master Mind KongMing gave ...

  8. 2015南阳CCPC G - Ancient Go dfs

    G - Ancient Go Description Yu Zhou likes to play Go with Su Lu. From the historical research, we fou ...

  9. 2015南阳CCPC D - Pick The Sticks 背包DP.

    D - Pick The Sticks Description The story happened long long ago. One day, Cao Cao made a special or ...

随机推荐

  1. HDU_1233_还是畅通工程

    还是畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  2. Linux的网卡由eth0变成了eth1或eth2,如何修复??

    背景:做linux下分布式测试的时候,重新安装了两个linux虚拟机,结果分布式脚本没有做好,分布式也没有做成. 今天想练练linux命令,打开vmware,启动linux1 虚拟机,使用ifconf ...

  3. Java基础(十)--static关键字

    static关键字通常应用在字段.方法.静态块,还有冷门一点的内容:静态内部类.静态导入 static字段: static字段也就是静态变量,是属于类的,被所有的对象所共享,只有当类初次加载的时候保存 ...

  4. 学习笔记7——使用Scanner获取键盘输入

    使用Scanner类可以很方面地获取用户的键盘输入,Scanner是一个基于正则表达式的文本扫描器,它可以从文件.输入流.字符串中解析出基本类型值和字符串值.Scanner类提供了多个构造器,不同的构 ...

  5. Spring Boot 与消息

    一.消息概述 在大多数应用中,可以通过消息服务中间件来提升系统的异步通信.扩展解耦和流量削峰等能力. 当消息发送者发送消息后,将由消息代理接管,消息代理保证消息传递到指定目的地. 消息队列主要有两种形 ...

  6. 巩固JavaSE基础--IDEA完成实战项目

    PS:学习完JavaSE基础后,需要有一个项目来测试自己的学习成果,并加以巩固.所以在这里,就让我们来学习下“一本糊涂账”项目吧.(此项目来源于Java自学网站) 项目完成效果图一览

  7. Opencv下双线性插值法进行图像放缩

    关于图像放缩的算法有很多,本文主要介绍双线性插值法进行图像放缩,本文参考了: http://www.cnblogs.com/funny-world/p/3162003.html 我们设源图像src的大 ...

  8. css--小白入门篇1

    一.引入 css用来描述html,学习css前我们先来学习html的基础标签的用法,再进入css的学习. 本教程面向小白对象,不会讲细枝末节深入的东西. 二.列表 列表有3种 2.1 无序列表 无序列 ...

  9. Luogu P1311 选择客栈

    暴力 我一开始做这道题先想到的就是暴力... 所以先说一下暴力的做法.首先在输入的时候讲花费小于P的位置标记下来,然后用两层循环枚举所有的两个客栈的组合方案.再用一层循环将两个客栈之间的位置扫一遍,如 ...

  10. Word2Vec的基本使用

    目录 1.建立模型 2.保存与加载模型 3.使用模型 gensim 是 Python 中一款强大的 自然语言处理工具,它包含了常见的模型,其中便有 Word2Vec 这一优秀的 词向量训练工具,可以使 ...