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 ...
随机推荐
- Java中Properties类的学习总结
学习目标: 1.认识properties文件,理解其含义,会正确创建properties文件. 2.会使用java.util.Properties类来操作properties文件. 一.认识prope ...
- Myeclipse安装svn插件(link方式)
Myeclipse安装svn插件(link方式) 优点:1.离线安装2.非侵入式 演示版本 myeclipse--myeclipse8.6 svn--subeclipse-site-1.6.5.zip ...
- sicily 1010. 单词数值
本题主要是Hash思想的应用 课程上机练习题 Contest ends in 8 months 27 days
- PCB特征阻抗计算神器Polar SI9000安装及破解指南
近年来,IC集成度的提高和应用,其信号传输频率和速度越来越高,因而在印制板导线中,信号传输(发射)高到某一定值后,便会受到印制板导线本身的影响,从而导致传 输信号的严重失真或完全丧失.这表明,PCB导 ...
- vim包,已自带所有常用插件及常用命令总结
/** ****************************************************************************** * @author Maox ...
- Window 8.1 计时器功能及图片切换
<Canvas Margin="450,0" Width="795" Grid.Column="1"> <Image Ma ...
- js----DOM的三大节点及部分用法
DOM有三种节点:元素节点.属性节点.文本节点. 一.用nodeType可以检测节点的类型 节点类型 nodeType属性值 元素节点 1 属性节点 2 文本节点 3 这样方便在js中对各个节点进行操 ...
- Oracle bbed 实用示例-----修改Data内容、恢复delete的rows
bbed 可以在db open 状态来进行修改,但是建议在做任何修改操作之前先shutdown db. 这样避免checkpoint 进程重写bbed 对block 的修改. 也避免oracle 在b ...
- float类型进行计算精度丢失的问题
今天一个案子,用户反映数量差异明明是 2.0-1.8,显示的结果却为0.20000005,就自己写了段方法测试了一下:package test1;public class Test2 {/*** @p ...
- WPF中的DataTemplate
<Window x:Class="DateTemplate应用.MainWindow" xmlns="http://schemas.microsoft.com/wi ...