POJ 3669 - Meteor Shower
来源:互联网 发布:windows 10 iot core 编辑:程序博客网 时间:2024/05/11 03:27
题目地址: http://poj.org/problem?id=3669
BFS。
简单搜索,记录每个炸弹落地的时间,在落地之前能走,之后不能走。
#include<iostream>#include<cstdio>#include<cstring>#include<queue>#define bug puts("here");using namespace std;int vis[330][330];int fx[]={0,0,0,1,-1};int fy[]={0,1,-1,0,0};struct Node{int x,y,t;};queue<Node>que;int bfs(){int k;Node tmp,now,nx;if(vis[0][0]==0) return -1; else if(vis[0][0]==-1) return 0;tmp.x=tmp.y=tmp.t=0;que.push(tmp);while(!que.empty()){now=que.front();que.pop();for(k=1;k<5;k++){nx.x=now.x+fx[k];nx.y=now.y+fy[k];nx.t=now.t+1;if(nx.x<0 || nx.y<0) continue;if(vis[nx.x][nx.y]==-1) return nx.t;if(nx.t>=vis[nx.x][nx.y]) continue;vis[nx.x][nx.y]=0;que.push(nx);}}return -1;} int main(){int m,k,t,x,y,xx,yy;scanf("%d",&m); memset(vis,-1,sizeof(vis));while(m--){scanf("%d%d%d",&x,&y,&t);for(k=0;k<5;k++){xx=x+fx[k];yy=y+fy[k];if(xx<0 || yy<0) continue;if(vis[xx][yy]==-1) vis[xx][yy]=t;else vis[xx][yy]=min(vis[xx][yy],t);}}printf("%d\n",bfs());return 0;}
- POJ 3669 - 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
- poj 3669 Meteor Shower
- POJ 3669 Meteor Shower
- poj 3669 Meteor Shower
- poj 3669 Meteor Shower
- POJ 3669 Meteor Shower
- poj 3669 meteor shower
- poj-3669-Meteor Shower
- POJ 3669:Meteor Shower
- POJ 3669 Meteor Shower
- POJ 3669 Meteor Shower
- POJ 3669 Meteor Shower
- [原创+源码]超简单:基于jQuery实现的选项卡(滑动门)效果
- 雁过也,月满西楼
- 句子翻转
- HDU 1166 点更新段查询线段树
- Linux卸载软件方法汇总
- POJ 3669 - Meteor Shower
- extern "C"的作用
- MFC中的CheckBox的使用
- 邂逅在华灯初上
- 3D玫瑰
- RDTSC汇编指令详解
- Read media
- iOS开发教程:Storyboard全解析-第一部分
- 羌笛声声胡笳怨,此心长寄天涯远