hrbust - 2239
|
||||||
Description | ||||||
鹿丸看见了一个胖子。 “胖子!” “啊?” 胖子转身,面对面发现站着的鹿丸。奇怪之于,他突然发现自己的脚动不了了。原来他中了鹿丸的影子模仿术。 “你想干嘛?”胖子怒吼。 “我想采访你一下,来,过来”。说着,鹿丸向前走去。胖子发现自己的行动被鹿丸控制了,鹿丸向前走,他也向前走。鹿丸左转,他也左转。 “叫我过去就过去?”胖子一生气,只听见duang的一声,天崩地裂,凭空从地上出现几座大山,不能通行。而此时,胖子和鹿丸的位置也被震的发生了变化,但是影子模仿术没被解除。此时两人一人面向东方,一人面向西方。 鹿 丸不料胖子有这等能耐。不过这下可费神了,怎么走到胖子旁边 呢?鹿丸往前走,胖子也会往前走,鹿丸不能往一个障碍物前进,但如果鹿丸前进时,胖子前进的位置是障碍物,那么胖子会狠狠的撞上去,不过实际的位置并不会 变化。注意,这里说的前是相对的,两人面向何方,那么前就是何方。当然,无论何时,鹿丸只要转向,胖子也会跟着转。 但是现在地形这么复杂,鹿丸需要思考一下,要怎么走才能用最少的步数让自己和胖子走到同一个地方,或者相邻也可以。毕竟和胖子挤一个地方还是挺憋屈的。 |
||||||
Input | ||||||
多组测试数据 每组测试数据第一行有两个数N,M (2<= N <= 20, 2 <= M <= 20) 表示场地的大小。 接下来有N行,每行有M个字符。描述场地的状态。其中'X'表示障碍,'P'表示胖子,'L'表示鹿丸。 |
||||||
Output | ||||||
对于每组数据,输出最小的总步数。如果不能相见,则输出"Smart PangZi!" | ||||||
Sample Input | ||||||
3 3 PXL ... ... 3 3 PX. ... .XL |
||||||
Sample Output | ||||||
3 2 |
||||||
Hint | ||||||
多提供几组样例数据 Input: 3 3 P.. L.. ... 3 3 XPX L.. ... 3 3 PXL .X. ... 3 3 PX. ..X L.. Output: 0 1 5 1 |
||||||
Source | ||||||
哈尔滨理工大学第五届ACM程序设计竞赛(热身) |
/** **/
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<cmath>
#include<string.h>
#include<queue>
#define maxn 25
using namespace std;
char ch[maxn][maxn];
int vis[maxn][maxn][maxn][maxn];
int n,m;
bool prime =false;
int tx[] = {,,,-};
int ty[] = {-,,,};
int dx[] = {,,-,};
int dy[] = {,-,,}; ///上 下 左 右
struct Node
{
int x1;
int y1;
int x2;
int y2;
int step;
Node()
{
x1 = ;
y1= ;
x2 = ;
y2 = ;
step = ;
}
} start;
//struct cmp
//{
// bool operator() (const Node a,const Node b)const
// {
// return ((a.x1 - a.x2) *(a.x1 - a.x2) +(a.y2 - a.y1)*(a.y2 - a.y1) > (b.x1 - b.x2) *(b.x1 - b.x2) +(b.y2 - b.y1)*(b.y2 - b.y1));
// }
//};
int check(int x1,int y1)
{
if(x1 >= && x1 <n && y1 >= && y1 <m) return ;
return ;
}
double solve(Node a)
{
return (a.x1 - a.x2) *(a.x1 - a.x2) +(a.y2 - a.y1)*(a.y2 - a.y1);
}
queue<Node>que;
int bfs()
{
while(!que.empty()) que.pop();
Node tmp,now;
vis[start.x1][start.y1] [start.x2][start.y2]= ;
start.step = ;
Node temp;
que.push(start);
while(!que.empty())
{
now = que.front();
que.pop();
int tt = solve(now);
if(tt == || tt == )
{
return now.step;
}
for(int i=; i<; i++)
{
temp.x1 = now.x1 + dx[i];
temp.y1 = now.y1+ dy[i];
if(temp.x1 < || temp.x1 >= n || temp.y1 < || temp.y1 >= m || ch[temp.x1][temp.y1] == 'X') continue;
int u = now.x2 + tx[i];
int v = now.y2 + ty[i];
if(u < || u>=n || v < || v >=m || ch[u][v] == 'X')
{
temp.x2 = now.x2;
temp.y2 = now.y2;
}
else
{
temp.x2 = u;
temp.y2 = v;
}
temp.step = now.step + ;
if(vis[temp.x1][temp.y1][temp.x2][temp.y2] == )
{
vis[temp.x1][temp.y1][temp.x2][temp.y2] = ;
que.push(temp);
}
}
}
return -;
}
int main()
{
//#ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
//#endif // ONLINE_JUDGE
while(~scanf("%d %d",&n,&m))
{
for(int i=; i<n; i++)
{
scanf("%s",ch[i]);
for(int j=; j<m; j++)
{
if(ch[i][j] == 'P')
{
start.x2 = i;
start.y2 = j;
}
else if(ch[i][j] == 'L')
{
start.x1 = i;
start.y1 = j;
}
}
}
memset(vis,,sizeof(vis));
int res = bfs();
if(res == -) printf("Smart PangZi!\n");
else printf("%d\n",res);
}
return ;
}
hrbust - 2239的更多相关文章
- poj 2239 二分图最大匹配,基础题
1.poj 2239 Selecting Courses 二分图最大匹配问题 2.总结:看到一个题解,直接用三维数组做的,很巧妙,很暴力.. 题意:N种课,给出时间,每种课在星期几的第几节课上 ...
- poj 2239 Selecting Courses(二分匹配简单模板)
http://poj.org/problem?id=2239 这里要处理的是构图问题p (1 <= p <= 7), q (1 <= q <= 12)分别表示第i门课在一周的第 ...
- 动态规划(背包问题):HRBUST 1377 金明的预算方案
金明的预算方案 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间金明自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过N元钱就行 ...
- [POJ] 2239 Selecting Courses(二分图最大匹配)
题目地址:http://poj.org/problem?id=2239 Li Ming大学选课,每天12节课,每周7天,每种同样的课可能有多节分布在不同天的不同节.问Li Ming最多可以选多少节课. ...
- [ An Ac a Day ^_^ ] hrbust 2291 Help C5 分形
开博客这么久从来没写过自己学校oj的题解 今天写一篇吧 嘿嘿 原题链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProble ...
- hrbust 2384 相同的不相同的字符串
Description 研究证明,汉的字阅读序顺是不会影响你明白这句话的意思的. 但是如果顺序差的太多也是会影响的,比如汉阅读顺的序字你就看不懂什么意思了. 那么多少算多呢?科学家芦苇给出证明,当两个 ...
- HRBUST - 2358 Magic network
HRBUST - 2358 思路:dfs序 + 树状数组 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimiz ...
- POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包)
POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ...
- HDU 1611 敌兵布阵 / HRBUST 1794 敌兵布阵(线段树)
HDU 1611 敌兵布阵 / HRBUST 1794 敌兵布阵(线段树) Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A ...
随机推荐
- 51NOD 1565:模糊搜索——题解
http://www.51nod.com/onlineJudge/questionCode.html#problemId=1565¬iceId=445588 有两个基因串S和T,他们只包 ...
- 洛谷 [SCOI2010]股票交易 | 单调性DP
题目链接 #include<cstdio> #include<algorithm> #include<cstring> #define N 2005 using n ...
- selenium - webdriver - ActionChains类(鼠标操作)
ActionChains 类提供了鼠标操作的常用方法: perform(): 执行所有 ActionChains 中存储的行为: context_click(): 右击: double_click() ...
- linux内核挂载文件系统的两种方式
1.nfs方式(挂载的为文件夹) bootargs=root=/dev/nfs nfsroot=192.168.1.105:/mnt/rootfs/rootfs ip=192.168.1.88:192 ...
- 给定一个数字n,不用for循环实现输出数组 [1,2,3,4,...,n]
一.for循环方式实现输出[1, 2, 3, ..., n] var n = 5; function test(n){ var arr=[]; for( var i = 1; i <= n; i ...
- 转:为什么在定义hashcode时要使用31这个数呢?
散列计算就是计算元素应该放在数组的哪个元素里.准确的说是放到哪个链表里面.按照Java的规则,如果你要想将一个对象放入HashMap中,你的对象的类必须提供hashcode方法,返回一个整数值.比如S ...
- 【转载】Lua中实现类的原理
原文地址 http://wuzhiwei.net/lua_make_class/ 不错,将metatable讲的很透彻,我终于懂了. --------------------------------- ...
- 八大疯狂的HTML5 Canvas及WebGL动画效果——8 CRAZY ANIMATIONS WITH WEBGL AND HTML5 CANVAS【收藏】
HTML5, WebGL and Javascript have changed the way animation used to be. Past few years, we can only a ...
- C题 hdu 1408 盐水的故事
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1408 盐水的故事 Time Limit: 2000/1000 MS (Java/Others) ...
- upupw注入by pass
http:' and updatexml(null,concat(0x5c,(/*!00000select SCHEMA_name*/from/*!information_schema*/.schem ...