2015CCPC南阳场 H - Sudoku

基于Matlab-Simulink的大林算法控制系统设计与振铃消除实验 本文详细介绍了基于Matlab-Simulink的大林算法控制系统设计与振铃消除实验。通过分析纯滞后系统的控制难题,探讨大林算法在工业控制中的应用优势,并提供Matlab-Simulink环境搭建、控制器D(z)设计、振铃消除及仿真实验的完整流程。文章还对比了大林算法与PID控制的性能差异,为工程实践提供参考。 阅读详情

比赛的时候读错了题意我去。。一直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);
	}
}




 



[UVM]UVM TLM2.0简介及应用实例分析 本文介绍了TLM2.0在UVM中的实现与应用。TLM2.0作为SystemC模型间的核心传输机制,相比TLM1.0提供了更丰富的特性,包括双向阻塞/非阻塞接口、时间标记和统一数据包。文章详细解析了TLM2.0在UVM中的接口实现方式,包括socket类型定义、数据传输机制以及时间标记处理。通过一个具体实例,展示了如何在UVM组件中使用TLM2.0的initiator和target socket进行数据传输,并说明了标准数据包格式和精确时间标记的优势。最后指出TLM2.0在UVM中的实现主要是为了与Syste 阅读详情

相关推荐

CST 仿真_NFC仿真

在CST中实现NFC天线单体的仿真

qq_43706810的博客 3961

CCPC-CDOJ-1222-Sudoku

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

命运在指间 583

瑞芯微RK3568开发板实战:Android11系统parameter.txt文件配置全解析(附常见问题排查)

本文深入解析了瑞芯微RK3568开发板在Android 11系统下parameter.txt文件的配置要点与实战技巧。作为BootLoader启动阶段的核心蓝图,该文件决定了硬件初始化、分区布局及电源管理。文章详细拆解了身份标识、GPIO控制(PWR_HLD)、命令行参数及分区表等关键字段的配置逻辑,并针对RK3568平台与Android 11特性提供了专项适配策略,最后附带了启动失败、分区异常等常见问题的深度排查方法。

php55的博客 895

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

mac安全干净卸载Anaconda3

主要原因是python命令没有映射到已经安装的python版本上,则需要添加。修改~/.bash_profile文件,将anaconda相关删除。现在想卸载Anaconda,恢复使用mac系统自带的Python。最后在mac的应用目录删除Anaconda。查看所有版本的python所在安装目录。或者不使用软连接映射,也可使用。再次查看python映射。查看python版本。建立软连接,添加映射。

buyue 5961

数据库和BI工程师面试题

 一.数据库 1.Oracle数据库,视图与表的区别?普通视图与物化视图的区别?物化视图的作用? 2.Oracle数据库,有哪几类索引,分别有什么特点? 3.Union与Union All的区别? 4.对游标的理解?游标的分类?使用方法? 5.如何查找和删除表中的重复数据?给出方法或SQL。 6.不借助第三方工具,怎么查看SQL的执行计划? 7.创建索引有哪些需要注意的要点?

web_go_run的专栏 1万+

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

RAGFlow源码解析-2、从源码构架ragflow v0.25.0镜像

本文详细记录了从零开始构建自定义RAGFlow镜像lt/ragflow:0.25.0的全过程。首先介绍了环境准备,包括检查Node.js、Docker版本和项目结构。然后详细说明了构建步骤:编译前端、创建自定义Dockerfile、构建镜像和验证。接着讲解了docker-compose配置修改要点,包括网络定义、MySQL依赖处理等。最后总结了部署过程中遇到的五个关键问题及解决方案,包括networks未定义、MySQL服务依赖、tiktoken文件缺失、数据库配置错误和端口映射问题。通过完整的操作流程和问

liutao841204的专栏 364

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

【零基础学习CAPL】——弹窗信息提示

不用手动制作Panel窗口,直接使用CAPL脚本实现弹窗提示。//没有wait超时,等待测试人员确认//有wait超时,对话框在超时后自动终止//有wait超时,可以显示一个资源,即对话框可以显示额外的信息。/*参数说明text:显示在弹窗中的内容,长度限制在4096字符timeout:弹窗自动结束的时间,单位:ms。若为0,则无超时控制heading:对话框文本上方的标题。字符串最大长度限制在256个字符。resource:URL或文件路径。字符串的最大长度是有限的(512个字符)。

LOVE135149的博客 264

08 rk3568 模拟smi mdio RTL8367RB(一)

前提需求:硬件连接普通gpio ,RTL8367RB需要mdio通信 使用的gpio是 MDC GPIO3_B3 (SMI时钟线) MDIO GPIO3_B4 (SMI数据线) 2. 数据结构与枚举 3.1 GPIO 初始化(地址映射) 内核无法直接访问物理地址,通过ioremap将 GPIO 控制器的物理地址映射为虚拟地址,后续通过虚拟地址操作 GPIO 寄存器。 3.2 设置引脚方向 3.3 设置电平 3.4 读取电平 6. SMI 总线时序实现 SMI 总线通信依赖严格的时序(起始信号、

qq_39451352的博客 541

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

制作3D地形图的方法-使用GlobalMapper和3ds Max软件

打开GlobalMapper软件,在菜单栏中选择“文件”>“打开数据文件”,然后选择相应的高程数据文件。在菜单栏中选择“渲染”>“渲染设置”,根据需要进行设置,如分辨率和输出格式。选择地形对象,点击菜单栏中的“渲染”>“材质编辑器”,然后根据需要调整材质属性,如颜色、纹理和光照等。在菜单栏中选择“工具”>“高程栅格和网格”>“创建地形网格”。在菜单栏中选择“文件”>“导出”>“导出栅格格式”。打开3ds Max软件,在菜单栏中选择“文件”>“导入”,然后选择之前导出的地形数据文件。步骤3:导出地形网格。

JqlScala的博客 1535

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

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

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

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

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

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

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

余额充值