把这个写出来是不是就意味着把   http://www.hacker.org/push  这个游戏打爆了? ~啊哈哈哈

其实只要找到一个就可以退出了  所以效率也不算很低的  可以直接DFS呀呀呀呀

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector> using namespace std; int dx[] = {-1,1,0,0};
int dy[] = {0,0,1,-1}; vector <char> ans;
int n,m;
char map[30][30];
char t[30][30];
bool found;
void copy() //每一次都需要复制一下地图
{
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
map[i][j]=t[i][j];
} void debug(int ax,int ay) //调试函数~~~
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(i==ax && j==ay){printf("@");continue;}
printf("%c",map[i][j]);
}
puts("");
}
puts("");
} bool ok(int xx,int yy)
{
if(xx<n && xx>=0 && yy<m && yy>=0)return true; return false;
} bool tag() //全部砖块都清除了
{
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(map[i][j]!='.')return false; return true;
} bool dfs(int posx,int posy)
{
if(found)return true;
if(tag())
{
found=true;
return true;
}
//debug(posx,posy);
for(int k=0;k<4;k++)
{
if(map[posx+dx[k]][posy+dy[k]]!='.' || !ok(posx+dx[k],posy+dy[k]))continue;
for(int i=1;i<=25;i++)
{
if(map[posx+i*dx[k]][posy+i*dy[k]]!='.' && ok(posx+i*dx[k],posy+i*dy[k]))
{
int tx=posx+i*dx[k];
int ty=posy+i*dy[k];
char cur1=map[tx][ty];
char cur2=map[tx+dx[k]][ty+dy[k]];
map[tx][ty]='.';
if(cur1!='a')
{
if(cur2=='.')
{
map[tx+dx[k]][ty+dy[k]]=cur1-1; //没有就减一级
}
else
{
map[tx+dx[k]][ty+dy[k]]=cur1-'a'+cur2; //如果后面有东西就要合体
}
} if(k==0)ans.push_back('U');
else if(k==1)ans.push_back('D');
else if(k==2)ans.push_back('R');
else ans.push_back('L'); dfs(tx,ty);
if(found)return true;
map[tx][ty]=cur1;
map[tx+dx[k]][ty+dy[k]]=cur2;
ans.pop_back(); break;
}
}
}
return false;
} int main()
{
while(scanf("%d%d",&m,&n)!=EOF)
{
found=false;
ans.clear();
for(int i=0;i<n;i++)
scanf("%s",t[i]); for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(t[i][j]!='.')continue;
copy();
if(dfs(i,j))
{
printf("%d\n%d\n",i,j);
break;
}
}
if(found)break;
}
for(int sb=0;sb<ans.size();sb++)
printf("%c",ans[sb]);
puts("");
}
return 0;
} /*
13 3
.............
...bb..bc....
............. 7 8
.......
.......
.....b.
.......
.aa.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 5965 扫雷(dfs)题解

    题意:给你一个3*n的格子,中间那行表明的是周围8格(当然左右都没有)的炸弹数量,上下两行都可以放炸弹,问你有几种可能,对mod取模 思路:显然(不),当i - 1和i - 2确定时,那么i的个数一定 ...

  3. HDU 1518 Square(DFS)

    Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end ...

  4. HDU 1015 Safecracker (DFS)

    题意:给一个数字n(n<=12000000)和一个字符串s(s<=17),字符串的全是有大写字母组成,字母的大小按照字母表的顺序,比如(A=1,B=2,......Z=26),从该字符串中 ...

  5. Hdu 1175 连连看(DFS)

    Problem地址:http://acm.hdu.edu.cn/showproblem.php?pid=1175 因为题目只问能不能搜到,没问最少要几个弯才能搜到,所以我采取了DFS. 因为与Hdu ...

  6. HDU 1501 Zipper(DFS)

    Problem Description Given three strings, you are to determine whether the third string can be formed ...

  7. HDU 5305 Friends(dfs)

    Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

  8. HDU 2553 N皇后问题(dfs)

    N皇后问题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 在 ...

  9. HDU 5934 Bomb(炸弹)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

随机推荐

  1. loadrunner ---<三>循环输出关联数组

    web_reg_save_param,将Ord参数值设定为ALL,则关联函数将自动把符合条件的关联值保存到参数数组里.在本例中,假设关联值返回三条记录,则LR分别将值保存到sor_1,sor_2,so ...

  2. struct 与 typedef struct

    1. 基本解释 typedef为C语言的关键字,作用是为一种数据类型定义一个新名字.这里的数据类型包括内部数据类型(int,char等)和自定义的数据类型(struct等). 在编程中使用typede ...

  3. Java并发编程-关卡

    CyclicBarrier 直译过来叫循环栅栏,它主要的方法就是一个:await().await() 方法没被调用一次,计数便会减少1,并阻塞住当前线程.当计数减至0时,阻塞解除,所有在此 Cycli ...

  4. Div 自适应屏幕大小

    http://blog.csdn.net/wodetiankong516/article/details/7827256 Background      有时, 我们需要将div或者其他的Elemen ...

  5. git 操作大全

    Git 以下内容整理自廖雪峰的git教程,主要用于个人方便使用git命令 git忽略已经被纳入版本库的文件 使用 git update-index –-skip-worktree [file] 可以实 ...

  6. cdh5.4、cm5.4 安装详细步骤

    安装准备: 1.centos6.5 64位 虚拟机,内存分配4G.硬盘位20G 2.cm5.4 cdh5.4 包 安装步骤 一.centos安装完后,进行系统配置 1.关闭防火墙 service ip ...

  7. c 按范围快速指定整数

    以前用过octave, 和matlab类似的软件, 指定范围非常方便 i = 1:10:100;  就可以得到 10 20 30 ... 100 这一系列的数据, 但是在c里面, 必须手动写循环, 太 ...

  8. css:outline

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  9. Myeclipse2014 自带的报表功能 与 Eclipse BIRT

    Myeclipse2014 自带的报表功能跟 Eclipse BIRT 差不多,但不兼容   1.只能是MyEclipse Web projects 或者 Report Web project不支持B ...

  10. vmware10中开启Intel VT-x

    记得刚接触linux的时候,是在win7下使用vmware虚拟机来安装linux,这样就可以方便的一边使用win7娱乐,一边在linux下进行学习.后来发现这种方式使得win7很卡,虚拟机也很卡,让人 ...