hdu 5547 Sudoku

网卡Inter (R) Wi-Fi 6 AX201突然故障 错误代码10,无法找到无线网络,蓝牙也无效了 问题描述 说来也是坑,简直就莫名其妙。早上在工位上,电脑一切正常(一直用的是无线网络),然后周五准备开周会了,所以拔掉电脑外接设备(电源线,鼠标,外接显示器)拿起电脑到会议室。到了会议室之后,无线网断开了(但一般是不会断开的,都在公司范围内),所以选择重连,但发现已经没有无线网络列表了。 电脑机型:联想YOGA 14s 2021 初步尝试 1、关闭开始飞行模式 - 无果 2、重启并重启 (因为前两天已经提醒过有windows更新,趁这个机会就更新并重启了)- 无果 3、下载鲁大师、驱动精灵、联想驱动管 阅读详情

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");
		}
	}
}



Vite 任意文件读取漏洞复现(CVE-2026-39363) Vite开发服务器 WebSocket中的fetchModule方法未实施server.fs访问控制,导致攻击者可通过WebSocket连接并读取服务器上的任意文件(CVE-2026-39363) 阅读详情

相关推荐

PLC控制气缸与电磁阀:从原理到实战编程详解

在工业自动化领域,很多工程师都能编写PLC程序控制电机启停,但当涉及到气缸和电磁阀的精确控制时,却常常遇到动作不协调、响应延迟甚至设备损坏的问题。这背后的关键不在于PLC编程本身,而在于对气动元件特性和控制逻辑的深入理解。 本文将从实际工程问题出发,深入解析气缸与电磁阀的工作原理、PLC控制逻辑设计、常见故障排查方法,并通过完整的梯形图实例,帮助读者掌握气动系统自动化编程的核心要点。无论你是刚接触PLC的初学者,还是希望提升气动控制技能的工程师,都能从中获得实用的技术指导。 1. 气缸与电磁阀在自动化控制中

weixin_42522374的博客 336

HDU 5547 Sudoku(dfs)

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

weixin_30460489的博客 166

同济大学C++mooc第五、六讲参考答案

同济大学C++moooc第5、6讲 第五讲 第一题 随机产生10个30~100(包括30,100)的正整数,求它们的最大值、最小值、平均值,并显示整个数组的值和结果。 代码片. // #include<iostream> const int n = 10; using namespace std; int main() { int s[n],i,j,t,sum=0; for (i = 0; i < n; i++)

cjzui6666的博客 1万+

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

Dify工作流实践—根据word需求文档编写测试用例到Excel中

文章介绍了用dify工作流实现从word需求文档到测试用例写入excel的详细落地过程

weixin_42476668的博客 5333

告别‘抓瞎’:CANoe的Trace、Graphics和Logging窗口实战技巧,高效分析总线故障

本文深入解析CANoe的Trace、Graphics和Logging窗口实战技巧,帮助工程师高效分析总线故障。通过智能过滤、可视化监控和智能日志管理,构建系统级问题定位工作流,显著提升车载网络故障排查效率。

weixin_42709044的博客 292

HDU - 5547 - Sudoku (dfs)

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

刘二狗的博客 479

【Python脚本】Python自动大麦网抢票,准点原价秒杀演唱会门票,拒绝黄牛交易!从我做起!!!1

你是否错过了周杰伦的票,最近又没抢到五月天的票,不要太难过,今晚有张学友的票,后天还有张杰的票,加油哦!

weixin_45841831的博客 6万+

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

OpenHarmony v4.1 Release设置应用随系统自动启动

OpenHarmony 4.1 版本中的 Ability Manager Service (AMS) 提供了应用自启动管理功能,允许系统控制哪些应用可以在系统启动时自动运行。这需要以下两个主要步骤:启用系统的自启动管理支持开发一个系统应用来管理自启动配置。

afufufufu的博客 1898

echarts 饼图(加载进度条动画效果)

1、外侧动画细线效果运动“custom”自定义系列中“renderItem”属性来实现,动态修改起始角度和终止角度。2、圆环使用" pie "类型添加两个data值来画百分比圆环,动态修改data中的值。

God's asylum的博客 1630

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

车载以太网网络测试-24【SOME/IP概述】

SOME/IP**(Scalable Service-Oriented Middleware over IP)是一种基于IP网络的面向服务的通信协议,专为汽车电子系统设计,支持服务发现、远程过程调用(RPC)和事件通知等功能。核心标准是由 AUTOSAR(汽车开放系统架构)定义,现已成为车载通信的重要标准之一(如AUTOSAR 4.0+)。SOME/IP的全称是,它是一种基于IP网络的面向服务的通信协议,广泛应用于汽车电子(AUTOSAR)和物联网领域。Scalable(可扩展的)含义。

车载网络测试工程师的博客 2186

【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的专栏 490

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

hdu 5547 Sudoku

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

zoro_n的博客 275

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

【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

大神养成中..... 1484

HDU 5547 Sudoku

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

weixin_56355841的博客 185

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的博客 367

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的博客 391

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的博客 536

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的博客 1100

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、付费专栏及课程。

余额充值