hdu 5547 Sudoku

Retinanet训练自己的数据(2):模型准备   在上一篇博客中,我们已经处理好了模型需要的数据集,下一步就是准备模型去训练数据。这里提醒一句,在制作数据时,最好将训练集和测试集人为分开。像Google tensorflow API,在制作数据时可以按比例自动生成,但是在上一篇文章中产生的数据(annotation.csv )其实都是用来训练的,如果你把自己的数据集全都转换了,那么恭喜你,最后你会发现没有数据集去测试了。   下面开始模型准... 阅读详情

Sudoku

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 710    Accepted Submission(s): 268


Problem Description
Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself. It looks like the modern Sudoku, but smaller.

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
The first line of the input gives the number of test cases,  T(1≤T≤100) .  T  test cases follow. Each test case starts with an empty line followed by 4 lines. Each line consist of 4 characters. Each character represents the number in the corresponding cell (one of '1', '2', '3', '4'). '*' represents that number was removed by Yi Sima.

It's guaranteed that there will be exactly one way to recover the board.
 

Output
For each test case, output one line containing  Case #x:, where  x  is the test case number (starting from 1). Then output 4 lines with 4 characters each. indicate the recovered board.
 

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
 

Source
 

Recommend
wange2014
 

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5547
题目大意:4个数字的数独。
解体思路:dfs,枚举填入数字1-4,每次判断填入数字是否符合就行。同poj2676。
代码如下:
#include <cstdio>
#include <cstring>
char s[10];
int a[10][10];
bool p;
bool ok(int x,int y)
{
	for(int i=0;i<4;i++)
	{
		if(i!=x && a[i][y]==a[x][y])
			return false;
	}
	for(int i=0;i<4;i++)
	{
		if(i!=y && a[x][i]==a[x][y])
			return false;
	}
	int nx=(x/2)*2;
	int ny=(y/2)*2;
	for(int i=nx;i<nx+2;i++)
		for(int j=ny;j<ny+2;j++)
		{
			if(i==x && j==y)
				continue;
			if(a[x][y]==a[i][j])
				return false;
		}
	return true;
}
void dfs(int x,int y)
{
	if(p || x==4)
	{
		p=true;
		return ;
	}
	if(a[x][y])
	{
		if(y==3)
			dfs(x+1,0);
		else
			dfs(x,y+1);
		if(p)
			return;
	}
	else
	{
		for(int i=1;i<=4;i++)
		{
			a[x][y]=i;
			if(ok(x,y))
			{
			//	printf("%d\n",i);
				if(y==3)
					dfs(x+1,0);
				else
					dfs(x,y+1);
			}
			if(p)
				return;
			a[x][y]=0;
		}
	}
}

int main(void)
{
	int n;
	scanf("%d",&n);
	for(int ca=1;ca<=n;ca++)
	{
		p=false;
		memset(a,0,sizeof(a));
		for(int i=0;i<4;i++)
		{
			scanf("%s",s);
			for(int j=0;j<4;j++)
			{
				if(s[j]=='*')
					a[i][j]=0;
				else
 					a[i][j]=s[j]-'0';
			}
		}
		dfs(0,0);
		printf("Case #%d:\n",ca );
		for(int i=0;i<4;i++)
		{
			for(int j=0;j<4;j++)
				printf("%d",a[i][j] );
			printf("\n");
		}
	}
}



手把手教你完成YOLOv10 PySide6目标检测界面搭建,使用Qt6设计YOLOv10检测系统,前台系统+后台管理系统开发实战,可用于大论文凑工作量或毕设必备,全网最详细教程 阅读详情

相关推荐

Linux运维踩坑实录:手把手教你修复LVM中PV显示[unknown]的诡异问题

本文详细解析了Linux运维中LVM物理卷(PV)显示[unknown]的故障现象及修复方法。通过分析问题根源、提供标准修复流程和特殊场景处理方案,帮助运维人员快速解决VG容量异常、PV状态丢失等问题,并分享预防措施与最佳实践,确保LVM存储系统的稳定运行。

weixin_26869081的博客 358

HDU 5547 Sudoku(dfs)

题目戳这 题意:给你一个4*4的方阵,里面包含的字符是1到4,还有*,然后要求把所有的*都替换成1到4,要求是每个上下左右四个2*2的小方阵里面1到4都要有,每一行每一列的数字不能相同,规则有点像数独。 思路:因为只有4*4,所以直接用dfs爆搜,然而也不能太暴力,直接搜到底再判断矩阵符不符合条件,这样太暴力了以至于最后一个样例都不能秒出,所以,要在每次给*赋值的时候判断是否能放这个数字,直接...

weixin_30460489的博客 169

【ShaderToy】开篇

写在前面呜呼,好久没有写博客了,好惭愧。题外话,感觉越大就越想家,希望可以一直和家人在一起,哪怕只是坐在一起不说话也觉得很温暖,一想到要分开眼睛就开始酸,哎。开学还是爬上来老实更新博客学习吧~今天爬上来一看,发现CSDN的博客编辑终于更新了!进步总是好的,以前的编辑器实在很捉急。使用这种标记语言的确方便了很多,但好像颜色字体没法设置?程序员果然对美观没什么追求。ShaderToy如果你还没听过Sha

candycat 8万+

Sudoku HDU - 5547 (暴力dfs)详解

Problem Description Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself. It looks like the modern Sudoku, but smaller. Actually, Yi Sima was playing it differe...

PCCCCC的博客 478

计算机组成与系统结构(第三版) 袁春风主编 课后习题答案讲解 第一、二章 计算机系统概述 数据的机器级表示

计算机组成与系统结构(第三版) 袁春风主编 课后习题答案讲解 第一、二章 计算机系统概述 数据的机器级表示

qq_73523062的博客 2142

Linux系统安装部署Redis完整教程(图文详解)

最近需要在Linux服务器安装部署Redis,参考了网上很多的文章,比较零碎,所以我自己写了一篇完整的Redis安装部署文档,在部署Redis之前重装了我的华为服务器,就是为了给大家一步步阐述我的操作过程,配合图文进行讲解更加通俗易懂!

黄团团的个人博客 6698

HDU - 5547 - Sudoku (dfs)

思路: 纯暴力会超时,每次填的时候需要判断当前行列是否满足情况,最后判断2x2的是否满足即可 ps:一定不要忘了回溯 #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include &lt...

刘二狗的博客 481

华为OD机试双机位C卷-几何平均值最大子数组(Py/Java/C/C++/Js/Go)

华为OD机试(机考)2026双机位C卷 【几何平均值最大子数组】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【几何平均值最大子数组】。

qq_45776114的博客 1373

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 Submission(s): 596Accepted Submission(s): 216 Problem Description Yi Sima was one of the bes...

anmob303090的博客 320

我的宠物狗学编程:从零开始的代码之旅

在这个示例中,我们定义了一个名为"interact"的函数,它通过输入函数获取用户的输入,并根据输入执行相应的代码块。在编程中,我们使用条件语句来根据不同的条件执行不同的代码块。对于我的狗狗,我将创建一个名为"feed"的函数来表示它的进食行为,并根据不同的条件输出不同的信息。在这个示例中,我们定义了一个名为"feed"的函数,并使用一个参数"food"来表示食物。对于我的狗狗,我将创建一个名为"dog_name"的变量来存储它的名字。对于我的狗狗,我将创建一个名为"bark"的函数来表示它的叫声。

2301_79331387的博客 340

【VTK】VTK中的光标样式

本文分享VTK中的光标设置相关内容技术,希望对各位小伙伴有所帮助!

qq_40041064的博客 1933

hdu 5547 Sudoku【dfs】

Sudoku Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 612    Accepted Submission(s): 223 Problem Description Yi Sima was one of the

mengxiang000000 1280

《UDS协议从入门到精通》系列——图解0x10:诊断会话控制

什么是诊断会话控制服务?切换模式时ECU要做哪些?有没有通信示例?本文全网最详解!!

车载系统攻城狮 1万+

【DFS】HDU5547Sudoku

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5547 Problem Description Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself. It looks like the modern Sudok

wlxsq的专栏 493

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

hdu 5547 Sudoku

点击打开链接 题意:  数度,填数。 暴力搜索。。。。。。。。。第一发,超时。 超时之后就一直wa。。。。原来是把回溯的标记删了。,,,,qaq #include #include #include #include #include #include #include #include #define ll long long #define x first

zoro_n的博客 275

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

【CCPC】hdu 5547 Sudoku【dfs】

题目:hdu 5547 Sudoku题意:给你一个4*4的数独,让你填其中未知的数 坑点 1:虽然斜线不用满足每个格子唯一,但是4*4的格子分成4个,每个2*2的格子必须满足数独 2:答案不唯一的输出所有的情况,即暴力搜索的时候要回溯。ac代码:#include <iostream> #include <string> #include <vector> #include <algori

大神养成中..... 1485

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

HDU 5547 Sudoku

5547 把4x4的区域划分成任意2x2的区域都含有1~4。

weixin_56355841的博客 186

HDU - 5547 Sudoku

题目描述:链接 Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself. It looks like the modern Sudoku, but smaller. Actually, Yi Sima was playing it different. First of al...

fanxingxue的博客 255

Hdu 5547 Sudoku(枚举)

Problem Description Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself. It looks like the modern Sudoku, but smaller. Actually, Yi Sima was playing it different. ...

shuati2000的博客 232

HDU5547-Sudoku

Sudoku                                                                               Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)

wang_128的博客 368

H - Sudoku HDU - 5547

Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself. It looks like the modern Sudoku, but smaller.  Actually, Yi Sima was playing it different. First of all, he tr...

ACM 470

Sudoku HDU - 5547

舞蹈链解决数独问题,也是很经典的一个数独问题 直接套用的书上的模版//leehaoze #include <iostream> #include <deque> #include <string> #include <vector> #include <queue> #include <cstdio> #include <stack> #include <algorithm> #include <

lee_haoze的博客 393

Sudoku HDU - 5547 数独 搜索

Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself. It looks like the modern Sudoku, but smaller.Actually, Yi Sima was playing it different. First of all, h...

baku6967的博客 537

hdu5547 Sudoku (暴力DFS)

题目点我点我点我 CCPC的H题,当时现场赛是连DFS都不会啊,唉o(︶︿︶)o 题目大意:数独 思路:直接暴力DFS,row[i][k]第i行数字为k的,col[i][k]第i列数字为k的。2*2的方块也必须是1234。#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #inclu

blanKey的博客 1101

2015 南阳 CCPC hdu5547 Sudoku(DFS)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5547 思路: 跟poj上面的那题数独一样,但是范围更小。 所以就写个水DFS加上一个水的暴力判断水过去了。 代码: #include #include #include #include using namespace std; int r[10][10],c[10][10],vis

hahahaha 1119

hdu 5547 Sudoku(dfs)

Sudoku Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 2533    Accepted Submission(s): 867 Problem Description Yi Sima was one of t

zcc的博客 270
上一篇: hdu 2074 叠筐
下一篇: hihoCoder#1269 : 优化延迟
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址