把这个写出来是不是就意味着把   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. vs2010 please select a valid location in the repository

    vs2010 please select a valid location in the repository AnkhSvn版本有问题,我后来使用2.1就ok了记录一下

  2. postgresql编译安装与调试(二)

    接前文postgresql编译安装与调试(一),继续说说postgresql的编译安装与调试. 上一篇已经详细说明了如何在Linux系统上编译安装postgresql,这次我们在此基础上简单讲讲如何在 ...

  3. c++中实现委托

    成员函数指针与高性能的C++委托(上篇) 撰文:Don Clugston 引子 标准C++中没有真正的面向对象的函数指针.这一点对C++来说是不幸的,因为面向对象的指针(也叫做"闭包(clo ...

  4. Eclipse安装配置PyDev插件

    Eclipse安装配置PyDev插件 关于PyDev PyDev是一个功能强大的 Eclipse插件,使用户可用 Eclipse 来进行 Python 应用程序的开发和调试.PyDev 插件的出现方便 ...

  5. 在VMware虚拟机中安装CentOS 7

    [声明] 欢迎转载,但请保留文章原始出处 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3917 ...

  6. windows下mysql5.7安装及配置

    装完msi后,复制my-default.ini文件,黏贴为my.ini文件,内容修改如下: # For advice on how to change settings please see# htt ...

  7. PermGen space Eclipse 终极解决方案

    1.选中项目右键 run or debug configurations... 2.在 VM arguments 加入  -Xms128m -Xmx512m -XX:PermSize=64M -XX: ...

  8. 55个高质量的Magento主题,助你构建电子商务站点

    Magento是一个功能丰富的开源电子商务平台(译者注:基于PHP的Zend Framework开发),在网店的外观.商品管理以及其它功能上,它给商家提供了前所未有的灵活和易用性.通过挑选一个合适的M ...

  9. Java学习日志-01-Hello World

    1.安装JDK1.7 2.安装eclipse 3.eclipse上写第一个java程序-hello world 先建工程,再建包,养成良好的习惯,然后新建类 若不先建立包,可能会提示"The ...

  10. NServiceBus-进阶

    下载 在本教程中我们将创建一个非常简单的订购系统,将从客户机向服务器发送消息.订单系统包括三个项目:客户端.服务器和消息,来完成这个任务,我们将执行以下步骤: 创建客户端项目 创建项目的消息 创建服务 ...