原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2821

  首先,题目描述给的链接游戏很好玩,建议先玩几关,后面越玩越难,我索性把这道题A了,也就相当于通关了。

  其实这道题算是比较水点搜索题,直接DFS + 回溯,但是题目描述不是很清楚使得很难下手,后来枚举题意才知道在边缘位置不会出现嵌套盒子,而且所有输入都肯定有解决的方案,所有的输入数据都是标准的。

 #include <stdio.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <stack>
using namespace std;
const int maxn = ; int dr[][] = {{, }, {-, }, {, }, {, -}};
char dd[] = {'R', 'L', 'D', 'U'};
char g[maxn][maxn];
char path[ * * ];
int a[maxn][maxn];
int r, c;
bool ok(int x, int y)
{
if(x >= && x < c && y >= && y < r && a[y][x] == )
return true;
return false;
} int dfs(int cy, int cx, int cnt, int len)
{
if(len == cnt)
return ;
for(int k = ; k < ; k++)
{
int x = cx + dr[k][];
int y = cy + dr[k][];
if(ok(x, y))
{
do
{
x += dr[k][];
y += dr[k][];
}
while(ok(x, y));
if(x >= && x < c && y >= && y < r)
{
int tmp = a[y][x];
a[y + dr[k][]][x + dr[k][]] += a[y][x] - ;
a[y][x] = ;
path[len] = dd[k];
if(dfs(y, x, cnt, len+))
return ;
path[len] = '\0';
a[y][x] = tmp;
a[y + dr[k][]][x + dr[k][]] -= a[y][x] - ;
}
} }
return ;
} int main()
{
int cnt;
while(scanf("%d %d", &c, &r) != EOF)
{
cnt = ;
for(int i = ; i < r; i++)
{
scanf("%s", g[i]);
for (int j = ; j < c; j++)
{
if(g[i][j] != '.')
cnt += g[i][j] - 'a' + , a[i][j] = g[i][j] - 'a' + ;
else
a[i][j] = ;
}
}
int i, j;
bool flag = false;
for(i = ; i < r; i++)
{
for(j = ; j < c; j++)
{
if(a[i][j] == && dfs(i, j, cnt, ))
{
flag = true;
break;
}
}
if(flag) break;
}
printf("%d\n%d\n", i, j);
for(int i = ; i < cnt; i++) putchar(path[i]);
putchar('\n');
}
return ;
}

  

HDU 2821 Pusher的更多相关文章

  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)

    Pusher Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others)Total Subm ...

  3. hdu 2821 Pusher (dfs)

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

  4. hdu 2821(dfs)

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

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

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

  6. hdu 3500 Fling (dfs)

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

  7. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  8. HDU——T 2818 Building Block

    http://acm.hdu.edu.cn/showproblem.php?pid=2818 Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

  9. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

随机推荐

  1. Wim技术之Wim文件的制作

    背景:操作的镜像文件为win8.1 update的ISO里的Wim文件 1.使用如下命令将支持WimBoot的instal.Wim文件转换成可以支持wimboot启动的映像文件 Dism /Expor ...

  2. Centos与win8.1的双系统

      背景:win8.1系统已经安装完成,并在此基础之上使用光盘或者U盘来安装centos系统,最终实现双系统   1.         在win8.1系统下查看磁盘及分区情况   2.         ...

  3. 《Cocos2d-x实战 JS卷 Cocos2d-JS开发》上线了

    感谢大家一直以来的支持! 各大商店均开始销售:京东:http://item.jd.com/11659698.html当当:http://product.dangdang.com/23659808.ht ...

  4. libjpeg 交叉编译动态库和静态库

    1.下载libjpeg库,解压之     得到了jpeg6b和libtool-2.2.4两个文件夹. 2.编译安装libtool工具.   这是配置libtool,这里需要注意:configure 参 ...

  5. 关于C++string的长度陷阱

    std::string s = ...; ..... assert(s.length() == strlen(s.c_str())); 一般认为这段代码是不会断言失败的,但是实际上这段代码可能是会断言 ...

  6. <邮件服务postfix+mysql>MAIL第二篇

    环境:本服务是建立在第一篇的基础之上的,最好搭建好第一篇 玩此服务的前提是你的系统装好了msql和postfix服务. Postfix+mysql主要是把邮件服务的发与mysql结合使用.当然mysq ...

  7. align=absMiddle属性设置

    AbsBottom 图像的下边缘与同一行中最大元素的下边缘对齐.AbsMiddle 图像的中间与同一行中最大元素的中间对齐.Baseline 图像的下边缘与第一行文本的下边缘对齐.Bottom 图像的 ...

  8. [大牛翻译系列]Hadoop(18)MapReduce 文件处理:基于压缩的高效存储(一)

    5.2 基于压缩的高效存储 (仅包括技术25,和技术26) 数据压缩可以减小数据的大小,节约空间,提高数据传输的效率.在处理文件中,压缩很重要.在处理Hadoop的文件时,更是如此.为了让Hadoop ...

  9. 为什么要用ajax

    Ajax应用程序的优势在于:1. 通过异步模式,提升了用户体验2. 优化了浏览器和服务器之间的传输,减少不必要的数据往返,减少了带宽占用3. Ajax引擎在客户端运行,承担了一部分本来由服务器承担的工 ...

  10. apache 多站点搭建

    一.apache配置多站点方法一 1.首先修改apache httpd.conf 文件 启用虚拟主机组件功能 取消 LoadModule vhost_alias_module modules/mod_ ...