2015南阳CCPC H - Sudoku 数独
H - Sudoku
Description
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
It's guaranteed that there will be exactly one way to recover the board.
Output
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 数独的更多相关文章
- 2015南阳CCPC H - Sudoku 暴力
H - Sudoku Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Yi Sima was one of the best cou ...
- 2015南阳CCPC E - Ba Gua Zhen 高斯消元 xor最大
Ba Gua Zhen Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description During the Three-Kingdom perio ...
- 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 ...
- 2015南阳CCPC L - Huatuo's Medicine 水题
L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous ...
- 2015南阳CCPC G - Ancient Go 暴力
G - Ancient Go Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Yu Zhou likes to play Go wi ...
- 2015南阳CCPC D - Pick The Sticks dp
D - Pick The Sticks Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description The story happened lon ...
- 2015南阳CCPC A - Secrete Master Plan 水题
D. Duff in Beach Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Master Mind KongMing gave ...
- 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 ...
- 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 ...
随机推荐
- dutacm.club_1089_A Water Problem_(dp)
题意:要获得刚好后n个'k'的字符串,有两种操作,1.花费x秒,增加或删除1个'k'; 2.花费y秒,使个数翻倍.问最少需要多少时间获得这个字符串. 思路:i为偶数个'k',dp[i]=min(dp[ ...
- Xamarin绑定ios静态库
以下是官方的步骤介绍,我就不再一步步解释了 https://docs.microsoft.com/zh-cn/xamarin/ios/platform/binding-objective-c/walk ...
- if语句,while语句,do whlie语句,循环语句
总结: 1.定义数组并赋值: var arr=[1,2,3,4]; 2.通过下标访问数组: var str=arr[0]; 3.自定义数组 var arr=new Array(); 4.数组的赋值 a ...
- 模板—splay
#include<iostream> #include<cstdio> #define cin(x) scanf("%d",&x) using na ...
- UVA - 10603 Fill(BFS求最小值问题)
题目: 给出三个杯子(没有刻度线)的容量,起初之后第三个杯子是满的,其他的两个杯子是空的,容量分别是a.b.c.问最少需要倒多少升水才能让某一个杯子中的水有d升?如果不能恰好做到d升,就让某一个杯子里 ...
- 使用 MyBatis 对表执行 CRUD 操作
说明: 1.CRUD: C -- create R -- read U -- update D -- delete 2.Mybatis 的 SQL 核心配置文件中 SQL 语句的参数的传 ...
- CentOS7安装Nginx及其相关
一.安装所需环境 gcc 安装 安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装. yum install gcc-c++ PCRE pcr ...
- Xcode 出现Thread 1: signal SIGABRT
代码语言:C 出现原因:数组初始化时,循环赋值越界. 例 bool type [30]; for (int i = 0;i<100;i++) type = 0;
- Jmeter使用笔记之断言
前言 Jmeter的断言方式有很多种,由于在工作中经常做的是API接口测试,所以这篇文章主要介绍如何对接口的字段进行解析,如何对解析出来的字段的值断言 了解API接口 Restful API 规范 协 ...
- 正确的在循环list的时候删除list里面的元素
s = [1,2,3,4,5] for i in s: s.remove(i) print(s) 输出结果:[2, 4] 1.当第一次删除后,后面的元素会前移,此时s=[2,3,4,5], 2.然 ...