2015CCPC南阳场 H - Sudoku

别再问ARM麒麟怎么装微信了!手把手教你用铠大师搞定Windows软件(飞腾/海思芯片实测) 本文详细介绍了如何在ARM架构的信创电脑(如飞腾/海思芯片)上使用铠大师安装和运行Windows软件,解决微信、Office等常用软件的兼容性问题。通过实测数据对比,铠大师在性能和易用性上显著优于传统方案,为麒麟系统用户提供了一套完整的解决方案。 阅读详情

比赛的时候读错了题意我去。。一直TLE+WA..

赛后看了题解才知道读错了题意。。愧疚啊我去。。这次比赛我读的两道题都读错了题意,坑死队友。。


H - Sudoku
Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u

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   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   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,  .   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   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

这里提供两种方法:

方法一:

思路:用res数组记录一下要填数字的点  用dfs枚举当前点可以填的所有数字。暴力搜索就可以了。

代码+注释如下:

#include<iostream> 
#include<algorithm>
#include<queue>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=7;
char mp[maxn][maxn];
bool vis[maxn][maxn],flag;
int res[maxn*maxn][2];
int resnum;
void input()//输入 
{
	resnum=0;
	flag=false;
	memset(vis,false,sizeof(vis));
	for(int i=1;i<=4;i++)scanf("%s",(&mp[i][0])+1);
	for(int i=1;i<=4;i++)
		for(int j=1;j<=4;j++)
			//记录一下要填数字的点 
			if(mp[i][j]=='*'){res[resnum][0]=i,res[resnum][1]=j,resnum++;} 
			else vis[i][j]=true;
}
void dfs(int step)
{
	if(flag||step==resnum){flag=true;return;}
	int tx=res[step][0],ty=res[step][1];
	int book[maxn]={false};
	//枚举4个2*2的小矩阵 
	if(tx<=2&&ty<=2)for(int i=1;i<=2;i++)for(int j=1;j<=2;j++)if(mp[i][j]!='*')book[mp[i][j]-'0']=true;
	if(tx<=2&&ty>2)for(int i=1;i<=2;i++)for(int j=3;j<=4;j++)if(mp[i][j]!='*')book[mp[i][j]-'0']=true;
	if(tx>2&&ty<=2)for(int i=3;i<=4;i++)for(int j=1;j<=2;j++)if(mp[i][j]!='*')book[mp[i][j]-'0']=true;
	if(tx>2&&ty>2)for(int i=3;i<=4;i++)for(int j=3;j<=4;j++)if(mp[i][j]!='*')book[mp[i][j]-'0']=true;
	//枚举列和行 
	for(int i=1;i<=4;i++)
	{
		if(mp[tx][i]!='*')book[mp[tx][i]-'0']=true;
		if(mp[i][ty]!='*')book[mp[i][ty]-'0']=true;
	}
	for(int i=1;i<=4;i++)
		if(!book[i])
		{
			mp[tx][ty]=i+'0';
			dfs(step+1);
			if(flag)return;
			mp[tx][ty]='*';
		}
}
int main()
{
	int T;
	scanf("%d",&T);
	for(int tcase=1;tcase<=T;tcase++)
	{
		input();
		dfs(0);
		printf("Case #%d:\n",tcase);
		for(int i=1;i<=4;i++)printf("%s\n",(&mp[i][0])+1);
	}
}


方法二:

思路:每次都填一次那个可以确定的点,不能填的点放在队列中,队列为空则OK!

用xvis[i][num]数组表示第i行num这个数出现过了没---------------yvis数组同理

再用jz[i][num]数组表示矩阵i中num这个数出现过了没。

然后每次都填那个可以确定的点 然后继续更新这三个标记数组,然后该点出列。直到队列为空。

代码如下:

#include<iostream> 
#include<algorithm>
#include<queue>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=10;
struct node
{
	int x,y;
};
bool xvis[maxn][5] ,yvis[maxn][5],jz[maxn][maxn];
char mp[maxn][maxn];
node temp,head;
queue<node>Q;
int findjz(int tx,int ty)//判断是在哪个矩阵
{
	if(tx<=2&&ty<=2)return 1;  
    if(tx<=2&&ty>2)return 2;
    if(tx>2&&ty<=2)return 3;
    return 4;
} 
void init()//初始化 
{
	memset(xvis,false,sizeof(xvis));
	memset(yvis,false,sizeof(yvis));
	memset(jz,false,sizeof(jz));
}
void input()
{
	for(int i=1;i<=4;i++)scanf("%s",mp[i]+1);
	for(int i=1;i<=4;i++)
		for(int j=1;j<=4;j++)
			if(mp[i][j]=='*'){temp.x=i,temp.y=j,Q.push(temp);}
			else
			{
				int num=mp[i][j]-'0';
				jz[findjz(i,j)][num]=xvis[i][num]=yvis[j][num]=true;//该数所处的行-列-矩阵都标记一下 }
			}
}
bool solve(node& head)
{
	int tx=head.x,ty=head.y;
	int sum=0,last;
	int pos=findjz(tx,ty);
	for(int i=1;i<=4;i++)
	{
		if(xvis[tx][i]||yvis[ty][i]||jz[pos][i])sum++;
		else last=i;
	}
	if(sum==3)//所以该要填的数字就可以确定了
	{
		xvis[tx][last]=yvis[ty][last]=jz[pos][last]=true;//更新标记 
		mp[tx][ty]=last+'0';
		return true;
	}
	return false;
}
int main()
{
	int T;
	scanf("%d",&T);
	for(int tcase=1;tcase<=T;tcase++)
	{
		init();
		input();
		while(!Q.empty()){head=Q.front(),Q.pop();if(!solve(head))Q.push(head);}
		printf("Case #%d:\n",tcase);
		for(int i=1;i<=4;i++)printf("%s\n",(&mp[i][0])+1);
	}
}




 



基于Vivado MIG IP核的DDR3读写实验(top_rom_ddr/ddr_top) 一、前言 关于Vivado MIG IP核详细配置可以参考我之前的文章:基于Vivado MIG IP核的DDR3控制器(DDR3_CONTROL) 关于MIG IP核的用户端的接口时序可以参考这篇文章:XILINX 的 MIG IP(非AXI4)接口时序以及控制 二、实验内容 本次实验的内容主要是通过MIG IP核向DDR3读写数据,DDR3的接口时序由ddr_top模块提供: ddr_top模块的数据来源是wr_fifo,wr_fifo的数据实际来自top_sd_photo模块(本实验仿真 阅读详情

相关推荐

动手学Moveit2|使用配置助手创建自己机械臂的功能包

今天没时间了,先生成功能包,下一步还需要装一些依赖才能运行,明天再补充下面的内容。

生活不止眼前的苟且 1万+

CCPC-CDOJ-1222-Sudoku

题目意思:   这道题和POJ2676一样,好像比那个还要简单,不知道比赛的时候为啥卡了 思路:   用3个标记数组,用来存取当前行和列还有2X2的小方格中数字是否出现,再加一个DFS就可以了 CODE #include #include #include #include #include #include using namespace std; int mx[5][5]; int

命运在指间 583

【第六届起重机创意大赛国一作品——资料分享】

文章目录前言一、比赛内容分析二、确定方案与作品模型1.方案简图2.作品模型三、电控部分控制思路单片机选择与资源分配拓展板的设计接线与走线代码分享总结

qq_19308801的博客 7781

2015南阳CCPC部分题目代码

我是部分按照难度来排序的,越简单的越前面。 首先是L题。 #include #include using namespace std; int main() { int t;scanf("%d",&t); for(int s = 1;s <= t;s ++) { int n; scanf("%d",&n); printf("Cas

sabervsarcher的博客 1046

从仿真到打样:PMOS栅极泄放电路设计全流程复盘与三个踩坑点总结

本文详细复盘了PMOS栅极泄放电路从仿真到打样的全流程设计,重点总结了三个关键踩坑点:三极管BE结过压击穿、静态功耗超标和栅极振荡现象。通过优化缓启动电路、改进保护设计和布局调整,最终实现18ms开通时间、190μs关断时间和8μA静态功耗的工业级性能指标,为类似电源开关设计提供实用参考。

weixin_28693683的博客 371

【RK3588 NPU性能调优实战】多线程异步推理YOLOv5,榨干6TOPS算力

本文详细解析了如何在RK3588 NPU上通过多线程异步推理优化YOLOv5目标检测性能,实现6TOPS算力的最大化利用。通过线程池设计、流水线化帧处理及避开内存带宽瓶颈等技巧,将NPU利用率从30%提升至82%,帧率显著提高至61.2FPS。文章还提供了环境配置、代码实现及性能对比数据,助力开发者高效部署AI模型。

weixin_29034963的博客 340

L - Huatuo's Medicine【ccpc】

L - Huatuo's Medicine Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit Status Description Huatuo was a famous doctor. He use identical bottles to carry

走一步再走一步 754

【MagicDrive环境配置】新手配俩星期版

1.创建一个新的环境conda create -n newdrive python==3.82.激活该环境conda activate newdrive3.下载MagicDrive源码 git clone --recursive https://github.com/cure-lab/MagicDrive.git,如果出现时间超时八成是网的问题,直接自己下载解压就好3.我的cuda版本是11.7,但11.7导致后续安装有冲突,因此进入。

m0_46261292的博客 2203

2015 ccpc 南阳国赛

A 2*2矩阵 问可不可以通过旋转 得到另外个 直接模拟 #include<stdio.h> #include<algorithm> #include<string.h> #include<string> #include<stdlib.h> #include<set> #include<ite...

weixin_30682127的博客 264

Vue3 - Element Plus 全局修改更换主题色配置详细教程,element-plus自定义主题色全局替换主色调强力解决方案,支持动态修改主题颜色/动态皮肤,将默认蓝色主题色更换为其他颜色!

vue3,nuxt3,element-plus,组件库,主题色,修改主题颜色,更换主题色,如何修改组件默认主题蓝色,项目主题色定制,修改失败,主题色覆盖不了,:root直接修改,hover颜色没改,自定义主题色,vue3全局设置elementPlus主题色最新详细修改教程,怎么修改全局的颜色,scss变量,覆盖原来的主题色改为自己的颜色,统一替换,有没有好办法,颜色不变,失败,无效,动态主题切换,主题颜色怎么在项目里直接改,plus主题色更换,覆盖默认主题色,最强最好用,设置主题色,换肤,皮肤,动态更换

🏆 前端领域优质创作者 1万+

概念解析 | 事件相机的原理 (含仿真代码)

在我们熟悉的世界里,传统相机就像一个勤勉的绘画师,每隔固定的时间就为我们勾勒出一幅完整的画面。但是,大自然中有太多瞬息万变的精彩场景,这种"定时绘画"的方式往往难以捕捉。于是,一种全新的"观察者"应运而生 -事件相机(Event Camera)。事件相机,就像是一群极其敏感的"像素哨兵",它们不再按部就班地等待指令,而是主动感知周围的变化,只有在光线强度发生显著变化时才会发出信号。这种革命性的设计,让事件相机拥有了传统相机难以企及的优势:超高的时间分辨率、极低的延迟、宽广的动态范围,以及出色的能效比。

NLOS的博客 1422

2015CCPC南阳场 D - Pick The Sticks

D - Pick The Sticks Time Limit:10000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 5543 Description The story happened long long ago. One

overload1997 858

让 SAP HANA 查询飞起来:彻底避开隐式类型转换的性能暗礁

SAP HANA性能优化:警惕隐式类型转换陷阱 隐式类型转换是SAP HANA项目中常见的性能隐患。当SQL表达式两侧数据类型不匹配时,系统会自动进行类型转换,这种看似便利的操作可能导致: 过滤条件无法下推,扫描范围扩大 列存引擎优势丧失,触发中间结果物化 执行计划走向低效路径 治理方案包括: 从源头统一数据类型,确保常用比较字段类型一致 将显式转换应用于常量而非整列 使用生成列预先转换存储,避免运行时计算 排查方法: 通过SQL Plan Cache定位高频查询 分析执行计划中的转换迹象 重点关注VARC

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 11万+

2015ccpc南阳个人题解

Secrete Master Plan 签到题,枚举4种情况判断相同即可。 #include<cstdio> #include<cstring> using namespace std; int a[4][2]; void turn() { int te = a[0][0]; a[0][0] = a[1][0], a[1][0] = a...

weixin_40191952的博客 346

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

2015南阳理工CCPC Sudoku

Sudoku Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  Status Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny

test 808

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

2015南阳CCPC H - Sudoku 暴力

H - Sudoku Time Limit: 1 Sec   Memory Limit: 256 MB 题目连接 无 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...

weixin_34290631的博客 196

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

2015南阳CCPC H - Sudoku 数独

H - Sudoku 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 diffe...

weixin_30258901的博客 153

【HDU5547 2015 CCPC 南阳国赛H】【DFS】Sudoku 4x4棋盘的填充

#include #include #define MS(x,y) memset(x,y,sizeof(x)) int casenum,casei; int n; char s[10][10]; bool line[4][4]; bool list[4][4]; bool sqr[4][4]; int bl[4][4]; bool dfs(int y,int x) { while(s[y][x]

snowy_smile的博客 1390

CCPC Sudoku

Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) SubmitStatus Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself. It l...

weixin_34216196的博客 144

2016 ICPC青岛赛 hdu5984 C Pocky

Pocky Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 156    Accepted Submission(s): 68 Problem Description Let’s talking about som

overload1997 2855

2017 icpc广西邀请赛 K.Query on A Tree (hdu 6191)可持久化字典树

Query on A Tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Monkey A liv

overload1997 1294

2012杭州赛区(浙江理工大学)J - Scaring the Birds

J - Scaring the Birds Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description It’s harvest season now!  Farmer John plants a lot of co

overload1997 1263

2017 ACM-ICPC 亚洲区(西安赛区)网络赛 G Xor lca+暴力

题目链接:https://nanti.jisuanke.com/t/17120 题意:给你一棵树,每个点都有权值,q次询问,每次询问给你a,b,k,问从点a到点b每隔k步的异或和是多少。 思路:现场没敢打,复杂度怎么算都不对。。。后来别人说可以1的情况lca其他暴力,我就试了一下,一开始是TLE,然后我各种迷之优化确实可以过。。。。走k步这里我是用了倍增的数组然后用logk的复杂度走k步。。。

overload1997 1164

2016 ICPC青岛赛 hdu5988 G.Coding Contest

Coding Contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 849    Accepted Submission(s): 156 Problem Description A coding cont

overload1997 948

2016 ICPC大连赛区 hdu5978 To begin or not to begin

To begin or not to begin Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 229    Accepted Submission(s): 175 Problem Description A b

overload1997 935

2012杭州赛区(浙江理工大学)H - Friend Chains

H - Friend Chains Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4460 Description For a group of people, there is an idea t

overload1997 774
上一篇: 2012杭州赛区(浙江理工大学)H - Friend Chains
下一篇: 2015CCPC南阳场 D - Pick The Sticks
overload1997
博客等级 码龄11年 328粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值