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 ...
随机推荐
- Server对象(是属性)
html, body { font-size: 10.5pt; } body { font-family: 微软雅黑, Helvetica, "Hiragino Sans GB", ...
- 获取输入设备的vid和pid
一.获取/dev/input/event16设备的vid和pid testhid.c #include <linux/types.h> #include <linux/input.h ...
- Creating your own header file in C
终于跑起来了,含自定义 include .h 的c语言程序,超开心呀! header files contain prototypes for functions you define in a .c ...
- 转:12C PDB 配置不同的PDB监听端口
How to Define PDB Listeners With Different Ports In A Multitenant Setup Goal This Note will discuss ...
- php 日期处理 例子
<?php date_default_timezone_set('PRC'); //默认时区 echo "今天:",date("Y-m-d",time() ...
- 初识Jmeter(一)
倒霉熊的推荐: 文本学习网址:http://m.open-open.com/m/doc/category/105 视频学习网址: 软件学习网:http://www.ask3.cn/index.html ...
- SuperSocket+unity 网络笔记
学习SuperSocket 必须要注意的 代码是 static void Main(string[] args) { WebSocketServer appServer = new WebSocket ...
- 模版引擎Handlebars语法(1)
<script src="handlebars.js"></script></head><body> <div id=&quo ...
- 转:Selenium Grid+JAVA +Windows 配置(Selenium 2.0)
Selenium-Grid 允许你在多台机器的多个浏览器上并行的进行测试,也就是说,你可以同时运行多个测试.本质上来说就是,Selenium-Grid 支持分布式的测试执行.它可以让你的测试在一个分布 ...
- SQL Server 2012 - 内置函数
文本函数 --系统函数位置: 可编程性→函数→系统函数 -- 查询ASCII码 select ASCII('a') --查询数值对应的ASCII码 select CHAR(97) --Left . R ...