Pusher

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others)
Total Submission(s): 754    Accepted Submission(s): 264
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   |   We have carefully selected several similar problems for you:  2822 2819 2820 2818 2824 
 

题意:

做了这题后告诉我一个真理,题意真的很重要!!

开始WA以为自己搞错题意了,然后上网看别人解题报告里的题意,让我迷惑的就是在边界的撞过去会怎样,- -本来是觉得应该会飞出去,这样挺好的~~

后来忘了是什么原因错了,一直TLE,就怀疑这个想法(好像没关系...),看到别人的是不能有这种情况,就按此思路再写再改,后来还是一直WA;于是再看一解题报告,

发现本来的才是对的:http://www.2cto.com/kf/201208/149755.html

题意大概如此,有然若干个可能叠起的方格放在某些格子上,选择任意点作为始点,Pusher可以沿某方向前进把格子推向正对方向的前一格,每次能减少1个,如果前一格有方格就叠起,如果前面一格已出界,就全部推掉了,减少n个。求一个可行解的始点及其操作。

dfs:

弄清楚提议后就好写了,弄了半天,心力交瘁= =我的代码可以优化,不过暂时不想看它了。

暴力n*m个点然后深搜可行解!

 //15MS    240K    2251 B    G++
#include<stdio.h>
#include<string.h>
char c[]="RDLU";
int mov[][]={,,,,,-,-,};
char g[][];
char root[];
int n,m,flag,sum;
int sx,sy;
int judge(int x,int y)
{
if(x>=&&x<n&&y>=&&y<m) return ;
return ;
}
void dfs(int x,int y,int cnt,int s)
{
if(flag) return;
if(sum==s){
flag=; root[cnt]='\0'; return;
}
for(int i=;i<;i++){
int tx=x+mov[i][];
int ty=y+mov[i][];
if(!judge(tx,ty) || g[tx][ty]) continue;
while(judge(tx,ty) && !g[tx][ty]){
tx+=mov[i][];ty+=mov[i][];
}
if(judge(tx,ty) && g[tx][ty]){
int ta=tx+mov[i][];
int tb=ty+mov[i][];
root[cnt]=c[i];
int temp=g[tx][ty];
if(g[tx][ty]==){
g[tx][ty]=;
dfs(tx,ty,cnt+,s+);
if(flag) return;
g[tx][ty]=;
}else{
if(judge(ta,tb)){
g[ta][tb]+=temp-;
g[tx][ty]=;
dfs(tx,ty,cnt+,s+);
if(flag)return;
g[ta][tb]-=temp-;
g[tx][ty]=temp;
}else{
g[tx][ty]=;
dfs(tx,ty,cnt+,s+temp);
if(flag)return;
g[tx][ty]=temp;
}
}
}
}
return;
}
int main(void)
{
while(scanf("%d%d",&m,&n)!=EOF)
{
int i,j;
flag=;
sum=;
memset(g,,sizeof(g));
memset(root,,sizeof(root));
for(i=;i<n;i++){
scanf("%s",g[i]);
for(j=;j<m;j++){
if(g[i][j]=='.') g[i][j]=;
else{
g[i][j]=g[i][j]-'a'+;
sum+=g[i][j];
}
}
}
for(i=;i<n;i++) if(!flag)
for(int j=;j<m;j++){
sx=i;sy=j;
if(!g[i][j])
dfs(i,j,,);
if(flag){
printf("%d\n%d\n",i,j);
puts(root);
break;
}
}
}
return ;
}
/*
3
7
...
...
.b.
...
...
.a.
...
*/

hdu 2821 Pusher (dfs)的更多相关文章

  1. hdu 2821 Pusher(dfs)

    Problem Description PusherBoy is an online game http://www.hacker.org/push . There is an R * C grid, ...

  2. hdu 2821 Pusher (dfs)

    把这个写出来是不是就意味着把   http://www.hacker.org/push  这个游戏打爆了? ~啊哈哈哈 其实只要找到一个就可以退出了  所以效率也不算很低的  可以直接DFS呀呀呀呀 ...

  3. HDU 2821 Pusher

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2821 首先,题目描述给的链接游戏很好玩,建议先玩几关,后面越玩越难,我索性把这道题A了,也就相当于通关 ...

  4. hdu 3500 Fling (dfs)

    Fling Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submi ...

  5. HDU.5692 Snacks ( DFS序 线段树维护最大值 )

    HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...

  6. hdu 2821(dfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2821 思路:一开始的时候没注意到,必须从map[i][j]==0的位置开始,然后就是dfs了,回溯的时 ...

  7. hdu 2821 学习一点dfs的小技巧吧。。 还是自己太弱了

    #include<iostream> #include<cstdio> #include<cstring> using namespace std; int r,c ...

  8. hdu 5727 Necklace dfs+二分图匹配

    Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...

  9. hdu 4499 Cannon dfs

    Cannon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4499 D ...

随机推荐

  1. 创建自己的网站博客--Hexo

    原文地址:https://www.xingkongbj.com/blog/hexo/creat-hexo.html 安装环境 安装 node 下载对应版本并安装 node . 安装 Git Windo ...

  2. scoped,会使设置UI组件库的样式识别不出来

    未设置 scoped 作用域:显示效果 设置作用域的效果:ui组件默认的值(你怎么设置都不管用)

  3. IntelliJ IDEA 12详细开发教程(一)思想的转变与新手入门【转】

    转载地址:http://bangqu.com/alicas/blog/433 从事软件开发工作以来,提高自己的开发效率,提高自己编码的规范,提高编码深度层次,这三样一直都是自己努力去追求的事情. 最近 ...

  4. tp5.0初入

    1.目录结构 |-application 应用目录 是整个网站的核心 |---|---index 前台目录 |---|-----|---controller 控制器 |---|-----|---mod ...

  5. js按钮点击事件

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  6. STM32无法使用IAR下载程序问题

    一开始建立了工程,然后程序下载都很正常.不知道什么情况自己下载代码之后,再重新下载代码无法成功. 我按照提示找了一下FlashStm32f30x8.flash这个文件,却发现IAR的目录下没并没有.又 ...

  7. 14,vue+uwsgi+nginx部署路飞学城

    有一天,老男孩的苑日天给我发来了两个神秘代码,听说是和mjj的结晶 超哥将这两个代码,放到了一个网站上,大家可以自行下载 路飞学城django代码 https://files.cnblogs.com/ ...

  8. Trident学习笔记(二)

    aggregator ------------------ 聚合动作:聚合操作可以是基于batch.stream.partiton [聚合方式-分区聚合] partitionAggregate 分区聚 ...

  9. dubbo本地搭建实例

    项目文件下载地址:http://download.csdn.net/detail/aqsunkai/9552711 概述     Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服 ...

  10. DOS程序员手册(十四)

    附录A ASCII字符集 十进制        十六进制      二进制              AscII         控制        按键 X10         X16        ...