HDU 5547 暴力
Sudoku
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1064 Accepted Submission(s): 362
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!!!
It's guaranteed that there will be exactly one way to recover the board.
****
2341
4123
3214
*243
*312
*421
*134
*41*
**3*
2*41
4*2*
1432
2341
4123
3214
Case #2:
1243
4312
3421
2134
Case #3:
3412
1234
2341
4123
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
char s[][];
int ans[][];
int l[][];
int r[][];
int p[][];
int judge(int x,int y)
{
if(x<&&y<) return ;
if(x>=&&y<) return ;
if(x<&&y>=) return ;
if(x>=&&y>=) return ;
}
void solve()
{
for(int i = ; i<; i++)
for(int j = ; j<; j++)
{
l[i][ans[i][j]] = ;
}
for(int j = ; j<; j++)
for(int i = ; i<; i++)
{
r[j][ans[i][j]] = ;
}
for(int i = ; i<; i++)
{
for(int j = ; j<; j++)
{
p[judge(i,j)][ans[i][j]] = ;
}
}
int flag = ;
int count = ;
while(flag)
{
flag = ;
for(int i = ; i<; i++)
{
for(int j = ; j<; j++)
{
count = ;
if(ans[i][j]) continue;
for(int k = ; k<=; k++)
{
if(l[i][k]==&&r[j][k]==&&p[judge(i,j)][k]==)
count++;
}
if(count == )
{
flag = ;
for(int k = ; k<=; k++)
{
if(l[i][k]==&&r[j][k]==&&p[judge(i,j)][k]==)
{
ans[i][j] = k;
l[i][k] = ;
r[j][k] = ;
p[judge(i,j)][k] = ;
}
}
}
}
}
}
}
int main()
{
int t,kase = ;
scanf("%d",&t);
while(t--)
{
memset(l,,sizeof(l));
memset(r,,sizeof(r));
memset(ans,,sizeof(ans));
memset(p,,sizeof(p));
for(int i = ; i<; i++)
{
scanf("%s",s[i]);
}
for(int i = ; i<; i++)
{
for(int j = ; j<; j++)
{
if(s[i][j] == '*') ans[i][j] = ;
else ans[i][j] = s[i][j] - '';
}
}
solve();
printf("Case #%d:\n",++kase);
for(int i = ; i<; i++)
{
for(int j = ; j<; j++)
{
printf("%d",ans[i][j]);
}
printf("\n");
}
}
return ;
}
HDU 5547 暴力的更多相关文章
- HDU 5547 Sudoku (暴力)
题意:数独. 析:由于只是4*4,完全可以暴力,要注意一下一些条件,比如2*2的小方格也得是1234 代码如下: #pragma comment(linker, "/STACK:102400 ...
- E - Sudoku HDU - 5547 (搜索+暴力)
题目链接:https://cn.vjudge.net/problem/HDU-5547 具体思路:对于每一位上,我们可以从1到4挨着去试, 具体判断这一位可不可以的时候,看当前这一位上的行和列有没有冲 ...
- HDU - 5547 数独(回溯法)
题目链接:HDU-5547 http://acm.hdu.edu.cn/showproblem.php?pid=5547 正所谓:骗分过样例,暴力出奇迹. 解题思想(暴力出奇迹(DFS+回溯)): 1 ...
- HDU - 5547 Sudoku(数独搜索)
Description Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself ...
- HDU 5547 Sudoku(DFS)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5547 题目: Sudoku Time Limit: 3000/1000 MS (Java/Others ...
- HDU 6351暴力枚举 6354计算几何
Beautiful Now Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- The 2015 China Collegiate Programming Contest H. Sudoku hdu 5547
Sudoku Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Subm ...
- HDU 5944 暴力
Fxx and string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)T ...
- hdu 4039 暴力
思路:用map将每个字符串与一个数字进行对应,然后暴力统计就好了 #include<cstring> #include<iostream> #include<cstdio ...
随机推荐
- spark第一篇--简介,应用场景和基本原理
摘要: spark的优势:(1)图计算,迭代计算(2)交互式查询计算 spark特点:(1)分布式并行计算框架(2)内存计算,不仅数据加载到内存,中间结果也存储内存 为了满足挖掘分析与交互式实时查询的 ...
- Html:upload
文件上传框 有时候,需要用户上传自己的文件,文件上传框看上去和其它 文本域差不多,只是它还包含了一个浏览按钮.访问者可以通 过输入需要上传的文件的路径或者点击浏览按钮选择需要上传 的文件. 代码格式: ...
- androidstudio 问题
Error:(1, 1) A problem occurred evaluating project ':app'. > Failed to apply plugin [id 'com.andr ...
- libevent linux安装
wget http://monkey.org/~provos/libevent-1.4.13-stable.tar.gzwget http://downloads.sourceforge.net/le ...
- TextureView+SurfaceTexture+OpenGL ES来播放视频(三)
引自:http://www.jianshu.com/p/291ff6ddc164 做好的Demo截图 opengl-video 前言 讲了这么多,可能有人要问了,播放视频用个android封装的Vid ...
- c++内存流
1.MemoryStream.h文件内容 ifndef _MEM_STREAM_H_ #define _MEM_STREAM_H_ #include <string> class CMem ...
- 第一个前台页面----xflow的页面
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%@ tagl ...
- java 方法的重载的语法规则
class People { float hello(int a,int b) { return a+b; } float hello(long a,int b) { return a-b; } do ...
- Box2d b2World的RayCast方法
RayCast方法: world.RayCast(callback:Function,point1:b2Vec2,point2:b2Vec2); * callback 回调函数 * point1 射线 ...
- Node.js学习 - Modules
创建模块 当前目录:hello.js, main.js // hello.js exports.world = function() { // exports 对象把 world 作为模块的访问接口 ...