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 ...
随机推荐
- cookie、json详解
什么是cookie 1.cookie是存储于访问者计算机中的变量2.cookie是浏览器提供的一种机制3.可以由js控制(设置.读取.删除)4.cookie可以实现跨页面全局变量可以跨越同域名下多个网 ...
- vue-element-admin使用常见问题
一.vue-element-admin添加快捷导航 这个组件是基于vue-i18n因此,首先在项目中安装i18n npm install --save vue-i18n 然后main.js中引入 im ...
- CAD如何动态绘制带面积周长的圆?
CAD绘制图像的过程中,画圆的情况是非常常见的,用户可以在控件视区点取任意一点做为圆心,再动态点取半径绘制圆. 主要用到函数说明: _DMxDrawX::DrawCircle 绘制一个圆.详细说明如下 ...
- Bullet:ORACLE Using SQL Plan Management(一)
SQL Plan Management如何工作? 当一个SQL硬解析时,基于成本的优化器CBO会生成多个执行计划,并从这些执行计划中选择一个优化器认为最低成本的执行计划. 如果SQL plan bas ...
- 行内块+calc+margin 三列布局
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- CQOI2007 涂色 paint (区间dp)
听说这道题是当年省选题 于是兴致勃勃拿来做了做 至于如何想到思路... 事实上没想象中那么简单... 脑阔挺疼的... (一开始都没看出来是区间dp) 想到可以区间dp,然后就似乎没啥大问题 枚举区间 ...
- centos7进入救援模式,修复错误配置
因某些修改操作,导致系统重启后无法正常启动,此时可进入救援模式,修复错误配置即可. OS:centos 7 1.重启系统后,进入grup引导页面,选中第一项然后按“e” 进入编辑模式: 2.通过↓键找 ...
- FileInputStream实现读取文件内容并输出到屏幕上
java输入输出流是站在程序的角度来说的.从文件中读取数据用输入流,向文件中写数据用输出流. package com.janson.day20180827; import java.io.FileIn ...
- 如何用纯 CSS 创作一个按钮文字滑动特效
效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. 在线预览 https://codepen.io/zhang-ou/pen/GdpPLE 可交互视频教 ...
- lastpass密码管理工具使用教程
现在移动互联网发展异常空气,无论访问哪个平台或者网站必须要注册账号,日子久了就会发现最痛苦的就是记住这些网站的密码.因为我们不可能将所有的网站都是设置同样的的账号密码,因为国内网站用户数据库被泄露的事 ...