Meteor Shower
来源:互联网 发布:ubuntu kernel devel 编辑:程序博客网 时间:2024/06/14 03:49
题意大概是:流星会在t 时刻毁掉(x , y)点,及其周围4点,一人从原点出发,在第一象限移动,问能否走到安全地区,如果能要输出到达安全地区的最短时间
简单的bfs
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>using namespace std;int v[330][330];int xx[5]={0,0,0,1,-1};int yy[5]={0,1,-1,0,0};struct P{ int x; int y; int t;};queue<P> q;int bfs(){ P a; a.x=0; a.y=0; a.t=0; if(v[0][0]==0)return -1;//原点一开始就被毁,则无解 if(v[0][0]==-1)return 0;//该点不受流星影响则已到达安全地区 q.push(a); while(!q.empty()) { P b; b=q.front(); q.pop(); for(int i=1;i<5;i++) { P e; e.x=b.x+xx[i]; e.y=b.y+yy[i]; e.t=b.t+1; if(e.x<0||e.y<0)continue;//不在第一象限 if(v[e.x][e.y]==-1)return e.t;//到达安全地区,返回该点的时间 if(e.t>=v[e.x][e.y])continue;//该点已被毁,不能再走 v[e.x][e.y]=0;//如果该点可走但是还没达到安全地区,则更改v的值,入队 q.push(e); } } return -1;//所有点都搜了也没有到达安全地区,则无解}int main(){ int m; cin>>m; memset(v,-1,sizeof(v));//没有走过的点和不会被流星毁灭的点为-1 while(m--) { int a,b,t1; cin>>a>>b>>t1; for(int k=0;k<5;k++) { int a1=a+xx[k]; int b1=b+yy[k]; if(a1<0||b1<0)//不在第一象限,不符条件 { continue; } else if(v[a1][b1]==-1)//该点被流星毁掉v数组存被毁掉的时间 { v[a1][b1]=t1; } else { v[a1][b1]=min(v[a1][b1],t1);//该点如果之前已经被流星毁掉,存最小的时间 } } } int sum=bfs(); cout<<sum<<endl; return 0;}
0 0
- Meteor Shower
- Meteor Shower
- Meteor Shower
- 流星雨 meteor shower
- POJ3669 Meteor Shower BFS
- POJ 3669 - Meteor Shower
- POJ 3699 Meteor Shower
- poj 3669 Meteor Shower
- poj 3669 Meteor Shower
- POJ-3669-Meteor Shower
- POJ 3669 Meteor Shower
- poj 3669Meteor Shower
- POJ-3669 Meteor Shower
- poj3669 Meteor Shower BFS
- POJ3669 Meteor Shower(BFS)
- Meteor Shower(3669)
- Poj 3699 Meteor Shower
- POJ3669 Meteor Shower 【BFS】
- 小白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连载三(整蛊小游戏)
- visual c++ 6.0的启动图标所在的目录
- 远程到服务器安装visualSVN server,出现Service 'VisualSVN Server' failed to start的解决方法
- c++构造函数详解
- DPI/PPI/dp/sp/px/pt 移动设计手册
- Meteor Shower
- ZOJ-1156
- MyEclipse项目改名
- github常见错误
- 工作点滴:办公椅。
- Java 转换流 简介
- UVA - 10895 Matrix Transpose
- 持续集成工具的选择
- 1001. A+B Format (20)