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 ...
随机推荐
- POJ_1088_(dp)(记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 95792 Accepted: 36322 Description ...
- 【Linux】CentOS安装Jenkins
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo sudo rpm -- ...
- 第二节:Css重写样式
一丶 进入浏览器---->F12----->找到要修改的区域的Style 进行重写Css样式 二丶打开新页面 window.open("/Persitent/OtherIndex ...
- 十二届 - CSU 1803 :2016(同余定理)
题目地址:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1803 Knowledge Point: 同余定理:两个整数a.b,若它们除以整数m所 ...
- Gym - 101670B Pond Cascade(CTU Open Contest 2017 贪心,二分)
题目: The cascade of water slides has been installed in the park recently and it has to be tested. The ...
- 54.string field聚合以及fielddata原理初探
主要知识点: 直接对分词的term进行聚合后果 设置fielddata=true 直接用.keyword进行聚合 doc value 的性能问题 一.直接对分词的term进行聚合后果 ...
- python3接口测试某个模块的很多接口有的用post有的用get
没啥好说的,啊哈哈 大神提示可以判断下用post还是get,但是加到哪里合适呢?仔细看认真看 耶耶耶
- oldboy python 3.5 week 1
#!/usr/bin/env python # -*- coding:utf-8 -*- ------------------------------------------- name = inpu ...
- idea 获取当前git最新分支
菜单栏VCS->选中Git 选择Fetch 获取最新分支
- lua 栈最后调用的函数,用于看调试信息
lua_getinfo int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); 返回一个指定的函数或函数调用的信息. 当用于取 ...