hdu 2102 A计划(优先队列+dfs)
改了好久,上午来实验室打出来了,运行就是不对,一直找啊找!还是没找到,最后突然停电了,打好的代码还没保存呢!
刚才来的时候又重新打了一遍!!!结果一个小小的错误wrong了好久!!!
在dfs值返回时两个NO的返回值不同写错了一个-100,一个-10,肯定不对了!!嘿嘿····,找到了,改了,提交了!对了!!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
struct node
{
int x,y,k;
int time;
friend bool operator<(node a,node b)
{
return a.time>b.time;
}
};
int visit[20][20][2];
int n,m,endx,endy,endk,ti,startx,starty,startk;
char a[20][20],b[20][20];
int dir[4][2]={0,1,1,0,-1,0,0,-1};
int judge(int x,int y,int k)
{
if(x>=0&&x<n&&y>=0&&y<m)
{
if(k==0&&a[x][y]!='*')
return 1;
if(k==1&&b[x][y]!='*')
return 1;
}
return 0;
}
int dfs(int startx,int starty,int startk)
{
priority_queue<node>q;
node cur,next;
int i,x,y,k;
cur.x=startx;cur.y=starty;
cur.k=startk;cur.time=0;
visit[startx][starty][startk]=1;
q.push(cur);
while(!q.empty())
{
next=q.top();
q.pop();
if(next.x==endx&&next.y==endy&&next.k==endk)
return next.time;
if(next.time>=ti)
return -100;
for(i=0;i<4;i++)
{
x=next.x+dir[i][0];
y=next.y+dir[i][1];
k=next.k;
if(judge(x,y,k)&&visit[x][y][k]==0)
{
if(k==0&&a[x][y]=='#')
{
cur.time=next.time+1;
cur.k=1;
cur.x=x;cur.y=y;
q.push(cur);
visit[x][y][1]=1;
continue;
}
if(k==1&&b[x][y]=='#')
{
cur.time=next.time+1;
cur.k=0;
cur.x=x;cur.y=y;
q.push(cur);
visit[x][y][0]=1;
continue;
}
cur.time=next.time+1;
cur.k=next.k;
cur.x=x;cur.y=y;
visit[x][y][k]=1;
q.push(cur);
}
}
}
return -100;
}
int main()
{
int T,i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&ti);
memset(visit,0,sizeof(visit));
for(i=0;i<n;i++)
scanf("%s",a[i]);
for(i=0;i<n;i++)
scanf("%s",b[i]);
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
if(a[i][j]=='#'&&b[i][j]=='#')
{a[i][j]='*';b[i][j]='*';}
if(a[i][j]=='#'&&b[i][j]=='*')
a[i][j]='*';
if(a[i][j]=='*'&&b[i][j]=='#')
b[i][j]='*';
}
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
if(a[i][j]=='P')
{
endx=i;endy=j;endk=0;
}
if(b[i][j]=='P')
{
endx=i;endy=j;endk=1;
}
if(a[i][j]=='S')
{
startx=i;starty=j;startk=0;
}
if(b[i][j]=='S')
{
startx=i;starty=j;startk=1;
}
}
int ans;
ans=dfs(startx,starty,startk);
if(ans<=ti&&ans!=-100)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102
hdu 2102 A计划(优先队列+dfs)的更多相关文章
- HDU 2102 A计划(BFS/DFS走迷宫)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- hdu 2102 A计划
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸 ...
- HDU 2102 A计划(两层地图加时间限制加传送门的bfs)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Time Limit: 3000/1000 MS (Java/Others) Me ...
- hdu 2102 A计划 具体题解 (BFS+优先队列)
题目链接:pid=2102">http://acm.hdu.edu.cn/showproblem.php?pid=2102 这道题属于BFS+优先队列 開始看到四分之中的一个的AC率感 ...
- [HDU 2102] A计划(搜索题,典型dfs or bfs)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 2102 A计划(DFS)
题目链接 Problem Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主 ...
- HDU 2102 A计划 (BFS或DFS)
题意:中文题. 析:是一个简单的搜索,BFS 和 DFS都可行, 主要是这个题有一个坑点,那就是如果有一层是#,另一个层是#或者*,都是过不去的,就可以直接跳过, 剩下的就是一个简单的搜索,只不过是两 ...
- hdu 2102 a计划问题。。 双层dfs问题
Problem Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长 ...
- HDU 2102 A计划 DFS与BFS两种写法 [搜索]
1.题意:一位公主被困在迷宫里,一位勇士前去营救,迷宫为两层,规模为N*M,迷宫入口为(0,0,0),公主的位置用'P'标记:迷宫内,'.'表示空地,'*'表示墙,特殊的,'#'表示时空传输机,走到这 ...
随机推荐
- Static File Middleware
[ASP.NET Core] Static File Middleware 前言 本篇文章介绍ASP.NET Core里,用来处理静态档案的Middleware,为自己留个纪录也希望能帮助到有需要 ...
- 获取iOS设备型号的方法总结
三种常用的办法获取iOS设备的型号: 1. [UIDevice currentDevice].model (推荐): 2. uname(struct utsname *name) ,使用此函数需要#i ...
- C++ new operator, delete operator, operator new, operator delete, new placement
http://www.younfor.com/cpp-new-placement-new-operator-new.html http://www.cnblogs.com/luxiaoxun/arch ...
- 对C语言中sizeof细节的三点分析
转自对C语言中sizeof细节的三点分析 1.sizeof是运算符,跟加减乘除的性质其实是一样的,在编译的时候进行执行,而不是在运行时才执行. 那么如果编程中验证这一点呢?ps:这是前两天朋友淘宝面试 ...
- POJ2200+全排列模拟
简单. 手动的实现全排列 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<a ...
- Loadrunner负载机agent
记录下来备用,若要一台服务器充当负载机,windows下必须启动magentproc.exe
- Struts2 interceptor使用经验小结
1. interceptor 调用Spring容器中的bean 在interceptor中常有需要调用Spring Bean的需要,其实很简单和Struts2的Action一样配置即可. Spring ...
- loadrunner throughput(吞吐量)理解
转自http://www.51testing.com/html/29/n-110129.html Throughput翻译为吞吐量,按照常规理解网络吞吐量表示在单位时间内通过网卡数据量之和,其中即 ...
- CDC 虚拟com口
现在很多电脑已经不带232了,特别是手提电脑.这使很多使用手提在外调试人员非常不方便.或许你可以买一条市面上usb转232转换线,但这些线抗干扰不是太好,在一些干扰大的地方会发生连接中断的问题,所以往 ...
- ElasticSearch大数据分布式弹性搜索引擎使用—从0到1
阅读目录: 背景 安装 查找.下载rpm包 .执行rpm包安装 配置elasticsearch专属账户和组 设置elasticsearch文件所有者 切换到elasticsearch专属账户测试能否成 ...