poj3669 流星雨啊!
来源:互联网 发布:rest in peace知乎 编辑:程序博客网 时间:2024/04/29 02:19
poj3669这道题我看了好像两三天的样子_(:з」∠)_,迷之TLE,迷之MLE,迷之WA_(:з」∠)_.后来发现,问题有点儿多.一共三个问题,
一是读入流星的时候,没有考虑前面流星对后面流星的影响.
二是:小主人公可以跑到300*300的格子外面.
三是:走路的时候,忘了判断路是否已经走过_(:з」∠)_.
#include<iostream>#include <cstdio>#include <queue>using namespace std;typedef pair<int,int> P;const int INF=20000;int M;int point[310][310];int time[310][310];int dx[]={0,0,-1,1,0};int dy[]={-1,1,0,0,0};queue<P> que;int bfs(int x,int y){ que.push(P(x,y)); while(que.size()){ P p=que.front(); que.pop(); if(point[p.first][p.second]==INF) { return time[p.first][p.second];} for(int i=0;i<4;i++){ int nx=p.first+dx[i]; int ny=p.second+dy[i]; if(nx>=0&&ny>=0&&time[p.first][p.second]<point[nx][ny]-1&&time[nx][ny]==0){ que.push(P(nx,ny)); time[nx][ny]=time[p.first][p.second]+1; } } } return -1;}int main(){ for(int i=0;i<310;i++){ for(int j=0;j<310;j++){ point[i][j]=INF; } } scanf("%d",&M); for(int i=0;i<M;i++){ int x,y,t; scanf("%d %d %d",&x,&y,&t); for(int j=0;j<5;++j){ int nx=x+dx[j]; int ny=y+dy[j]; if(nx>=0&&ny>=0&&point[nx][ny]>t){ point[nx][ny]=t; } } } int a=bfs(0,0); cout<<a<<endl;}
阅读全文
0 0
- poj3669 流星雨啊!
- poj3669 流星雨
- POJ3669 Meteor Shower 流星雨【预处理】【广搜】
- POJ3669
- poj3669
- poj3669
- poj3669
- poj3669
- poj3669
- poj3669
- POJ3669
- poj3669
- 流星雨
- 流星雨
- 流星雨
- bfs--poj3669
- BFS POJ3669
- poj3669 BFS
- Android动画学习(四)之属性动画学习
- android面试题,各大企业常见的android面试题之二
- 单链表寻找环,寻找环的入口点
- 从零开始react入门(一)
- JavaDay05数组
- poj3669 流星雨啊!
- android binder 通信
- DeepFace--Facebook的人脸识别&& FaceNet--Google的人脸识别
- SecureCRT操作
- 归一化、标准化和正则化的关系
- String类的实现
- 2017 Multi-University Training Contest
- DOM
- 图像处理26:图像金子塔