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 ...
随机推荐
- iOS 之单例,代理,通知,KVO,Block全能解析
//单例 //.h + (Instannce *)shareInstance; //.m static Instannce *instance = nil; @implementation Insta ...
- 滚动视图和页面控制UIScollView,UIpageControlDemo
//// ViewController.m// UIScollView//// Created by hehe on 15/9/25.// Copyright (c) 2015年 wang.h ...
- 【转载】#273 - Parameter Modifier Summary
Here's a summary of the different parameter modifiers and how the behavior changes for each, when us ...
- ajax学习计划
来自http://segmentfault.com/a/1190000004322487?utm_source=Weibo&utm_medium=shareLink&utm_campa ...
- DB2&&oracle-培训内容
DB2 1 Data Sharing架构,高可用 2 DB2的对象主要有以下几类:database,storage group, Tablspace, indexspace, table,index ...
- 【风马一族_windom】 批量修改相同文件类型的后缀
难题:有时因为某种原因,修改一堆文件的类型,重复操作次数多,浪费时间也跟着多,收获也会相当少. 提问:对于软件而言,可量化的,有规律的操作,可以使用程序来进行替代. 特性:在微软操作系统上,不同后缀的 ...
- SDRAM控制器
1 初始化以及load mode 寄存器1 初始化以及load mode 寄存器 2 时间表 这里会有几个重要的时间周期: 3 AUTO REFRESH (自动刷新) 4 CAS(CL delay) ...
- [C/C++]在头文件中使用static定义变量意味着什么
文章出处:http://www.cnblogs.com/zplutor/ 看到有一位同学在头文件中这么写: static const wchar_t* g_str1 = - static const ...
- CentOS6.4安装LAMP环境
1.配置防火墙,开放80.3306端口 vi /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport - ...
- yum被锁定
使用Yum的时候 提示yum被搜定了 . Another app is currently holding the yum lock; waiting for it to exit... 解决办法 ...