HDU2821 Pusher HDU3500 Fling DFS搜索

C语言——利用矩阵LU分解法求逆、行列式 本章介绍了LU分解法,以及如何利用LU分解法求逆、行列式,针对每个公式、原理、代码进行了详细介绍,希望可以给大家带来帮助。 阅读详情
 

Pusher

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others)
Total Submission(s): 169 Accepted Submission(s): 67
Special Judge


Problem Description
PusherBoy is an online game http://www.hacker.org/push . There is an R * C grid, and there are piles of blocks on some positions. The goal is to clear the blocks by pushing into them.

You should choose an empty area as the initial position of the PusherBoy. Then you can choose which direction (U for up, D for down, L for left and R for right) to push. Once the direction is chosen, the PusherBoy will walk ahead until he met a pile of blocks (Walking outside the grid is invalid). Then he remove one block from the pile (so if the pile contains only one block, it will become empty), and push the remaining pile of blocks to the next area. (If there have been some blocks in the next area, the two piles will form a new big pile.)

Please note if the pusher is right up against the block, he can't remove and push it. That is, there must be a gap between the pusher and the pile. As the following figure, the pusher can go up, but cannot go down. (The cycle indicates the pusher, and the squares indicate the blocks. The nested squares indicate a pile of two blocks.)


And if a whole pile is pushed outside the grid, it will be considered as cleared.

Input
There are several test cases in each input. The first two lines of each case contain two numbers C and R. (R,C <= 25) Then R lines follow, indicating the grid. '.' stands for an empty area, and a lowercase letter stands for a pile of blocks. ('a' for one block, 'b' for two blocks, 'c' for three, and so on.)


Output
Output three lines for each case. The first two lines contains two numbers x and y, indicating the initial position of the PusherBoy. (0 <= x < R, 0 <= y < C). The third line contains a moving sequence contains 'U', 'D', 'L' and 'R'. Any correct answer will be accepted.

Sample Input
  
3 7 ... ... .b. ... ... .a. ...

Sample Output
  
4 1 UDU
Hint
Hint: The following figures show the sample. The circle is the position of the pusher. And the squares are blocks (The two nested squares indicating a pile of two blocks). And this is the unique solution for this case.

Source

Recommend
gaojie
 
建议先去玩玩这个游戏^_^
题意:n*m的格子上有一些方块放在某些格子上,一个格子可能有几个方块,用'a'-'z'来表示方块数量。
初始的时候可以选择任意空地作为Pusher初始点,Pusher选择一个方向,然后向这个方向前进直到遇到有方块的格子,Pusher把这个格子的方块清除一个,并把它向前推一格(向前不能出界),如果前面一格有方块,那么这些方合起来放在这个格子中。Pusher和有方块的格子之间至少要有一个空地才能推动。
题解:
就是赤裸裸的DFS搜索,不过要注意一些细节。
枚举每一个有方块的格子周围距离为2的空地作为初始点,
枚举方向推动Pusher,注意回溯时要还原状态。
代码:
#include<cstdio>
#include<cstring>
#include<cctype>

int n,m,num,cnt,a[35][35],dir[4][2]={0,-1,0,1,-1,0,1,0};
char map[35][35],p[]="LRUD",path[625];
int ok(int x,int y)
{
	if(x<0||y<0||x>=n||y>=m)
		return 0;
	if(a[x][y]==0)
		return 1;
	return -1;
}
int dfs(int x,int y,int pos)
{
	int i,xx,yy,tx,ty;
	for(i=0;i<4;i++)
	{
		xx=x+dir[i][0];
		yy=y+dir[i][1];
		if(ok(xx,yy)!=1)
			continue;
		do
		{
			xx+=dir[i][0];
			yy+=dir[i][1];
		}while(ok(xx,yy)==1);
		if(ok(xx,yy)&&ok(tx=xx+dir[i][0],ty=yy+dir[i][1])&&a[xx][yy])
		{
			int t=a[xx][yy];
			path[pos]=p[i];
			if(t==1||a[tx][ty])
				cnt--;
			if(cnt==0)
			{
				num=pos;
				return 1;
			}
			a[tx][ty]+=t-1;
			a[xx][yy]=0;
			if(dfs(xx,yy,pos+1))
				return 1;
			a[xx][yy]=t;
			a[tx][ty]-=t-1;
			if(t==1||a[tx][ty])
				cnt++;
		}
	}
	return 0;
}
int main()
{
	while(~scanf("%d%d",&m,&n))
	{
		int i,j,k,x,y,flag=1,f[35][35]={0};
		for(i=num=0;i<n;i++)
		{
			scanf("%s",map[i]);
			for(j=0;j<m;j++)
				if(isalpha(map[i][j]))
					num++,a[i][j]=map[i][j]-'a'+1;
				else
					a[i][j]=0;
		}
		for(i=0;i<n&&flag;i++)
			for(j=0;j<m&&flag;j++)
				if(a[i][j])
					for(k=0;k<4&&flag;k++)
					{
						x=i+dir[k][0]*2;
						y=j+dir[k][1]*2;
						if(ok(x,y)>0&&!f[x][y])
						{
							f[x][y]=1;
							cnt=num;
							if(dfs(x,y,0))
								flag=0;
						}
					}
		printf("%d\n%d\n",x,y);
		for(i=0;i<=num;i++)
			printf("%c",path[i]);
		puts("");
	}
}

 

Fling

Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 227 Accepted Submission(s): 96


Problem Description
Fling is a kind of puzzle games available on phone.
This game is played on a board with 7 rows and 8 columns. Each puzzle consists of a set of furballs placed on the board. To solved a puzzle, you need to remove the furballs from board until there is no more than one furball on the board. You do this by &#180;flinging&#180; furballs into other furballs, to knock them off the board. You can fling any furballs in four directions (up, left, right, down). The flung furball stops at the front grid of another one as soon as knocking it. And the knocked furball continues to rolling in the same direction until the last knocked one goes off the board. For instance, A furball at (0, 0) rolls right to the furball at (0, 5), then it will stop at (0, 4). Moreover, the latter will roll to right. You cannot fling a furball into a neighbouring furball, the one next to in any of four directions. However, it is permitted for a rolling ball knocks into a ball with a neighbour in that direction.



Input
The input contains multiple test cases.
For each case, the 7 lines with 8 characters describe the board. &#180;X&#180; represents a empty grid and &#180;O&#180; represents a grid with a furball in it. There are no more than 12 furballs in any board.
Each case separated by a blank line.


Output
For each case, print a line formatted as "CASE #NUM:", where NUM is the number of current case.
Then every &#180;fling&#180; prints a line. Each line contains two integers X, Y and a character Z. The flung furball is located at grid (X, Y), the top-left grid is (0, 0). And Z represents the direction this furball towards: U (Up), L (Left), R (Right) and D (Down);
Print a blank line between two cases.
You can assume that every puzzle could be solved.
If there are multiple solve sequences, print the smallest one. That is, Two sequences A (A1, A2, A3 ... An) and B (B1, B2, B3 ... Bn). Let k be the smallest number that Ak != Bk.
Define A < B :
(1) X in Ak < X in Bk;
(2) Y in Ak < Y in Bk and X in Ak = X in Bk;
(3) Z in Ak < Z in Bk and (X,Y) in Ak = (X,Y) in Bk;
The order of Z: U < L < R < D.


Sample Input
  
XXXXXXXX XXOXXXXX XXXXXXXX XXXXXXXX XOXXXXOX XXXXXXXX XXXXXXXX XXXXXXXX XOXOXOOX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX

Sample Output
  
CASE #1: 4 6 L 1 2 D CASE #2: 1 1 R 1 4 L 1 3 R

Author
EvilSeraph

Source

Recommend
zhouzeyong
 
和上面一个题类似,球会被推出去。
代码:
#include<cstdio>
#include<cstring>

int t,n=7,m=8,num,dir[4][2]={-1,0,0,-1,0,1,1,0};
int path[15],f[15];
char map[15][15],p[]="ULRD",pathc[15];
int ok(int x,int y)
{
	if(x<0||y<0||x>=n||y>=m)
		return 0;
	return 1;
}
int dfs(int pos)
{
	if(pos==num-1)
		return 1;
	int i,j,k,x,y,tx[15],ty[15];
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			if(map[i][j]=='O')
				for(k=0;k<4;k++)
				{
					int flag=0,cnt=0;
					x=i+dir[k][0];
					y=j+dir[k][1];
					if(map[x][y]=='O')
						continue;
					while(ok(x,y))
					{
						if(map[x][y]=='O')
						{
							flag=1;
							tx[cnt]=x;
							ty[cnt++]=y;
						}
						x+=dir[k][0];
						y+=dir[k][1];
					}
					if(flag)
					{
						map[i][j]='X';
						for(int ii=0;ii<cnt;ii++)
						{
							map[tx[ii]][ty[ii]]='X';
							map[tx[ii]-dir[k][0]][ty[ii]-dir[k][1]]='O';
						}
						path[pos]=i*m+j;
						pathc[pos]=p[k];
						if(dfs(pos+1))
							return 1;
						map[i][j]='O';
						x=i+dir[k][0];
						y=j+dir[k][1];
						while(ok(x,y))
						{
							if(map[x][y]=='O')
								map[x][y]='X';
							x+=dir[k][0];
							y+=dir[k][1];
						}
						for(int ii=0;ii<cnt;ii++)
							map[tx[ii]][ty[ii]]='O';
					}
				}
	return 0;
}
int main()
{
	while(~scanf("%s",map[0]))
	{
		int i,j;
		num=0;
		memset(f,0,sizeof(f));
		for(i=1;i<n;i++)
			scanf("%s",map[i]);
		for(i=0;i<n;i++)
			for(j=0;j<m;j++)
				if(map[i][j]=='O')
					num++;
		dfs(0);
		if(t)
			puts("");
		printf("CASE #%d:\n",++t);
		for(i=0;i<num-1;i++)
			printf("%d %d %c\n",path[i]/m,path[i]%m,pathc[i]);
	}
}

实战指南:如何用DCCRN模型提升语音增强效果(附代码示例) 本文提供了基于DCCRN模型进行语音增强的实战指南。通过深入解析复数网络如何协同处理语音的幅度与相位信息,并附有完整的PyTorch代码实现,帮助开发者从数据准备、模型搭建到训练调优,构建高效的实时语音增强系统,有效提升嘈杂环境下的语音清晰度。 阅读详情

相关推荐

SAP ERP销售应收&成本科目确定

ERP作为业财一体软件,其中最核心的就是业务与财务模块的自动集成,无需财务进行手工做账,提高工作效率的同时降低人工操作产生的误差。今天浅浅的分享一下SD模块生成会计凭证时,借贷项确定的系统配置。一般项目上借贷项、科目都有FICO提供,但是具体的集成配置是在SD这边。

weixin_43657667的博客 1525

常用的英文缩写和短信缩写

常用的英文缩写和短信缩写 P.S (postscript附录) @TEOTD – At the end of the day 最后 121 – One-to-one 一对一 10X – Thanks 谢谢 10Q – Thank you 谢谢你 1CE – Once 从前 1DR – I wonder 我想 1NAM – One in a million 100个里

越努力越幸运! 3万+

scratch绘制四个三角形 2024年6月中国电子学会 图形化编程 scratch编程等级考试二级真题和答案解析

​ scratch绘制四个三角形 一、题目要求 2024年6月电子学会图形化编程Scratch等级考试二级真题 1、准备工作 1.保留默认角色小猫; 2.添加背景Stars。 2、功能实现 1 .隐藏角色小猫,设置画笔裙始位置为(0,0),画笔颜色为黄色,画笔的粗细为5; 2. 点击绿旗,绘制如下图所示图形,三角形的边长为50。 二、案例分析 1、角色分析 角色:小猫 2、背景分析 背景:Stars背景 3、前期准备 1. 保留默认的小猫不变 ​

青少年编程学习指导 1666

rm: 无法删除 "xxxxx.o" : 输入/输出错误.

rm: 无法删除 "xxxxx.o" : 输入/输出错误. 碰到无法删除的文件,以为完蛋了,要重装。 后面重启一下就可以了 转载于:https://www.cnblogs.com/ioio/p/4894508.html...

6537

【Educational Codeforces Round 16】Codeforces 710C Magic Odd Square

构造解

YHaX的博客 1253

2023 年牛客多校第二场题解

A Link with Checksum 题意:定义如下的类 CRC 的校验和算法。 string Link_CRC(string D) { P = 0x04C11DB7; int n = D.length(); D += "00000000 00000000 00000000 00000000"; for (int i = 1; i <= n; i++) { if (D 的最高位为 1) { 去掉 D 的

m0_52048145的博客 5564

[LeetCode]Surrounded Regions

https://leetcode.com/problems/surrounded-regions/ 解法一:深搜 考虑一种特殊情况: OOOOOOOOOO XXXXXXXXXO OOOOOOOOOO OXXXXXXXXX OOOOOOOOOO XXXXXXXXXO OOOOOOOOOO OXXXXXXXXX OOOOOOOOOO XXXXXXXXXO  应该change "if(j

gqk289的专栏 3616

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

1.解压 tar zxvf wmsdk_bundle-xxxxxxx cd wmsdk_bundle-xxxxxxx 2. make installpkgs 3.安装gcc-arm-none-eabi http://blog.csdn.net/al86866365/article/details/47424727 4.编译测试 make boot2 5.下载 Error:

al86866365的专栏 87万+

中心性的度量---度中心性,间接中心性,紧密中心性,特征向量中心性

网络分析中,经常会用到中心性这个概念。通常在中心性的分析角度上有两种出发点:中心度和中心势。 &amp;amp;amp;amp;amp;npsb;&amp;amp;amp;amp;amp;npsb;中心度表示一个节点在网络中处于核心地位的程度;中心势表示整个图的紧密程度。换句话说,度表示单个节点的性质,而势表示整个图的性质。 目前有四种中心性的分析方法,分别是:度中心性(degree centrality),间接中心性(betweenness centrali...

努力努力再努力的博客 7万+

速卖通API:item_get - 获得aliexpress商品详情

万邦速卖通获得aliexpress商品详情 API 返回值说明 ![在这里插入图片描 请求参数 请求参数:num_iid=32667038134 参数说明:num_iid:EBAY商品ID 点击注册测试地址(获取Key和secret) Request address: //api.onebound.cn/aliexpress/api_call.php? num_iid=32667038134&api_name=item_get&lang=zh-CN&key=&secr

QQ569893796的博客 1342

前端 JavaScript 常用插件/框架/工具库汇总

很多时候 web 网页上需要判断或监听浏览器(系统)的网络状态。 Navigator onLine 属性 onLine 属性是一个只读的布尔值,声明了系统是否处于脱机模式,如果系统属于脱机状态,则返回 false,否则返回 true。 注:在 IE 4+ 中,用户可以在浏览器中选择脱机工作,当脱机工作被选后,系统就进入了脱机状态,内容将从缓存进行读取。 语法:navigator.onLin...

蚩尤后裔-汪茂雄 5642

新之大帝图片

欢迎各位拜访我的博客!

wtfsb的博客 5768

hdoj1240

Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description You're in space. You want to get home. There are asteroids. You don't w

◆◇丶生如夏花。谁来订阅我的悲伤 892

Connecting to https://XXXXXXXXXXXXXXXXXXXXXXXX:8440/ca

INFO 2017-08-05 01:14:38,849 HeartbeatHandlers.py:115 - Stop event received INFO 2017-08-05 01:14:38,849 NetUtil.py:125 - Stop event received INFO 2017-08-05 01:14:38,849 ExitHelper.py:53 - Performi

wangjunji34478的专栏 47万+

码农的表白

码农的创意的数字表达爱意的方式,包括利用编程技巧生成心形和玫瑰图案,以及使用二进制和压缩算法进行信息加密。首先,通过在Sublime Text中输入特定的数字序列并搜索所有“9”,意外地生成了一种心形图案。接着,介绍了两种在HTML中使用Canvas元素绘制动态心形的方法,可通过将提供的JavaScript代码直接粘贴至Chrome浏览器的地址栏来预览效果。此外,还展示了一种用“x”和“o”代表二进制的“1”和“0”的编码方式,通过简单的C++程序实现对“I Love You”的编码与解码。进一步,文

生活在别处 9万+

xxxxxxxxxxxxxx

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

malebird的专栏 25万+

counting 1 bits C implementations

counting 1 bits C implementations (idea) by bis Thu Oct 18 2001 at 4:34:42 Here are C implementations of a

wisage的专栏 1万+

xxx.h:369:19: error: reference to ‘xxxxx‘ is ambiguous

xxxxx 有多个地方定义,需要区分使用 那一个, 可以指定 namespace ,如:::A::xxxxx。

sun007700的专栏 4914

Verifying 000xxxxx ( 0%) Verify failed between address 0xxxxxx and 0xxxxxx Leaving target processor

1. 首先要根据address后面的两个地址判断出错的到底是什么器件。一般情况出现错误的大多是存储器。     判断的方法是根据sopc中的地址,或者是system.h中的地址,查找相应出错的器件。 2. 检查硬件焊接是否正常。     很多时候有些问题是硬件焊接造成的,这个主要针对的是自己焊接的板子,一旦地址数据总线有任何焊接问题,都会出现verify failed错误。 3.

Studying…… 4万+

UTF-8 and Unicode FAQ for Unix/Linux

UTF-8 and Unicode FAQ for Unix/Linuxby Markus Kuhn This text is a very comprehensive one-stop information resource on how you can use Unicode/UTF-8 on POSIX systems (Linux, Unix). You will find here b

遗失角度 1万+

Code Sign error: Provisioning profile 'xxxxxxxxxxxxxxxxxxxxxxxxx'

在Xcode中当你在更新了你得证书而再重新编译你的程序,真机调试一直会出现 Code Sign error: Provisioning profile ‘XXXX’ can't be found是不是会另你很恼火。下面说说解决方法,让你很好的解决这个问题。            1.关闭你的项目,找到项目文件XXXX.xcodeproj,在文件上点击右键,选择“显示包内容”(Show Pack

NightWish 7162

XXXXXXXXX开发板XXXXXXXXX

芯片类型:xczu3eg-1sfvc784i。

thing 2489

强大的二进制编辑器软件hex editor neo,软件体积小巧,功能强大,软件支持对二进制及十六进制文件的编辑、替换、删除等

强大的二进制编辑器软件hex editor neo,软件体积小巧,功能强大,软件支持对二进制及十六进制文件的编辑、替换、删除等一系列操作,好用方便。1、独特的十六进制代码编辑和处理软件2、高性能和代码优化工具,可帮助开发人员快速,轻松地操作二进制文件,3、对于软件开发人员来说是宝贵的实用程序,因为它可以帮助他们编辑原始和准确的内容直接搜索文件,研究任何.exe文件的功能4、用于编辑任何大小文件的解决方案5、功能强大的二进制文件编辑器,具有出色的性能和合理的价格软件特色1、编辑任何大小的文件;

海康威视摄像头OCX控件

海康威视摄像头OCX控件,可以显示摄像头图像、抓取图像、保存图像等,在C#、VB、组态王中都可以使用。带:OCX控件接口说明(V2.3).doc

上一篇: HDU4067 Random Maze 最小费用最大流 福州网络赛
下一篇: POJ 2286 HDU 1667 ZOJ 2396 The Rotation Game IDA*迭代加深搜索
power721
博客等级 码龄18年 176粉丝 135原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值