HDU 2821 Pusher
原题链接: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的更多相关文章
- hdu 2821 Pusher(dfs)
Problem Description PusherBoy is an online game http://www.hacker.org/push . There is an R * C grid, ...
- hdu 2821 Pusher (dfs)
Pusher Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others)Total Subm ...
- hdu 2821 Pusher (dfs)
把这个写出来是不是就意味着把 http://www.hacker.org/push 这个游戏打爆了? ~啊哈哈哈 其实只要找到一个就可以退出了 所以效率也不算很低的 可以直接DFS呀呀呀呀 ...
- hdu 2821(dfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2821 思路:一开始的时候没注意到,必须从map[i][j]==0的位置开始,然后就是dfs了,回溯的时 ...
- hdu 2821 学习一点dfs的小技巧吧。。 还是自己太弱了
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int r,c ...
- hdu 3500 Fling (dfs)
Fling Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submi ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDU——T 2818 Building Block
http://acm.hdu.edu.cn/showproblem.php?pid=2818 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- Android 图片开发内幕系列第一篇
前言:本来我是做电视应用的,但是因为公司要出手机,人员紧张,所以就抽调我去支援一下,谁叫俺是雷锋呢!我做的一个功能就是处理手机中的应用ICON,处理无非就是美化一下,重新与底板进行合成和裁剪,用到了很 ...
- (转)Centos5.5安装MONO2.10.8和Jexus 5.0开启Linux平台.net应用新篇章
注:本文只做本人记录使用,也可供大家参考,有兴趣的可以一起讨论. 安装步骤 1.yum –y update 2.安装Mono源码安装需要的库 yum -y install gcc gcc-c++ bi ...
- AD查询1000条限制和解决方案
公司的一个项目要从AD上取数据,为了测试性能,批量在AD上创建了2000多个用户.但是用java程序获取所有用户的时候会报错或者只能取到1000条数据. 条数据. 用org.springfra ...
- 各个公司的来源/The etymology of company
1.List of Company Etymology 下面的维基百科词条是比较有名的一些公司的名称的来源 List of company name etymologies 2.Atmel : adv ...
- WEB-INF简介
WEB-INF简介 WEB-INF是Java的WEB应用的安全目录.所谓安全就是客户端无法访问,只有服务端可以访问的目录. 如果想在页面中直接访问其中的文件,必须通过web.xml文件对要访问的文件进 ...
- 【风马一族_Java】java的一种IDE
IntelliJ IDEA 14 下载地址: IntelliJ IDEA 14 下载 分享几个license: (1) key:IDEA value:61156-YRN2M-5MNCN-NZ8D2-7 ...
- Xcode中为代码添加特殊标记
有时候,我们需要在代码中搜索特殊的符号或者代码段,根据符号或使用搜索功能导航代码段效率并不算高.为了使用普通的英语标识重要的代码片段,可在代码中插入特殊格式的注释.这些注释不会在应用程序中添加任何特殊 ...
- 一款仿PBA官网首页jQuery焦点图的切换特效
一款仿PBA官网首页jQuery焦点图的切换特效,非常的简单大方, 在对浏览器兼容性的方面做了不少的功夫.IE6也勉强能过去. 还是一款全屏的焦点图切换特效.大气而清新.很适合简介大方的网站. 下图还 ...
- jquery 处理字符串 【转】
1,去掉空格 var txt=$.trim($("txt1").val()); 2,转为数字 txtNum=Number($.trim(txt)) + 1; var thi ...
- 验证中文、英文、电话、手机、邮箱、数字、数字和字母、Url地址和Ip地址的正则表达式
Helper类代码 public class Helper { #region 单列循环 private Helper() { } private static Helper instance = n ...