poj 3669-Meteor Shower(简单bfs)
来源:互联网 发布:卡通农场数据恢复 编辑:程序博客网 时间:2024/04/30 00:40
我真是傻逼
这么简单的一个bfs我都不会写了。。 今天傻逼了一天;
这个题目开始不会写bfs了,后来神奇的超时,然后又是wa
超时是因为没有处理走过的路程,就是走过的路再走一遍,那样会有不必要的循环,甚至得出错误答案;
但是这不是最气的,最气的是,我的错误原因是因为INF的值写错了 ,我自己改了一个#define INF 0x7f 也就是121 而事实上应该是#define INF 0x7fffffff
还有一个点i,j也能写错,还有对于dis的数值的储存,一开始认为是最大值,而事实上应该是最小值,(因为在小t是就已经毁掉了)
今晚上第一次心态炸雷
#include <iostream>#include<queue>#include<cstring>#include<cstdio>#include<algorithm>#define INF 0x7ffffffusing namespace std;const int maxn=500+5;int dx[]={0,0,1,-1};int dy[]={1,-1,0,0};int dis[maxn][maxn];struct P{ int x,y; P(int xx=0,int yy=0){x=xx;y=yy;}};int bfs(){ queue<P>s; while(s.size()) s.pop(); s.push(P(0,0)); int d[maxn][maxn]; memset(d,0,sizeof(d)); d[0][0]=0; while(s.size()) { P a=s.front(); s.pop(); if(dis[a.x][a.y]==INF) { return d[a.x][a.y]; } for(int i=0;i<4;i++) { int xx=a.x+dx[i],yy=a.y+dy[i]; if(xx>=0&&yy>=0&&(dis[xx][yy]>d[a.x][a.y]+1)&&d[xx][yy]==0) { s.push(P(xx,yy)); d[xx][yy]=d[a.x][a.y]+1; } } } return -1;}int main(){ int m; scanf("%d",&m); for(int i=0;i<maxn;i++) for(int j=0;j<maxn;j++) dis[i][j]=INF; //memset(dis,INF,sizeof(dis)); // cout<<dis[0][0]<<endl; for(int i=0;i<m;i++) { int x,y,t; scanf("%d%d%d",&x,&y,&t); dis[x][y]=min(dis[x][y],t); for(int j=0;j<4;j++) { int xx=x+dx[j],yy=y+dy[j]; if(xx>=0&&yy>=0) dis[xx][yy]=min(dis[xx][yy],t); } } int ans=bfs(); cout << ans<< endl; return 0;}
今晚上第一次心态炸了,我真傻,,,
高神坐我背后我没有跟他说话,不知道说啥他又不认识我,而且我还连这么简单的题都a不出来,真可笑,
他们说高神是我男神,额不好意思我不认男神,不过确实性质是有点像的,不过很羞耻,现在依旧这么垃圾,还是没法跟高神面对面交流
总是感到自己很垃圾,鞭策自己要进步,可是还是没有什么长进,也没有好好刷什么题,
黄,我拜托你,不要总是做一个纸老虎,会说,不会做,关键时刻还掉链子,
你,清醒点,加油!
还有要期末了,注意一下,你的成绩!!!
阅读全文
0 0
- poj 3669-Meteor Shower(简单bfs)
- POJ 3669 Meteor Shower (BFS)
- POJ 3669 Meteor Shower (BFS + 预处理)
- POJ 3669 Meteor Shower (bfs)
- POJ 3669 Meteor Shower(bfs)
- poj 3669 Meteor Shower(BFS)
- POJ 3669 Meteor Shower(BFS)
- POJ 3669-Meteor Shower(BFS)
- POJ - 3669 - Meteor Shower(bfs)
- POJ 3669 Meteor Shower(BFS)
- POJ 3669 Meteor Shower(BFS)
- POJ 3669 Meteor Shower(BFS)
- POJ 3669 Meteor Shower(bfs)
- POJ 3669 Meteor Shower(BFS)
- poj 3669 Meteor Shower (bfs)
- POJ 3669-Meteor Shower(BFS)
- POJ 3669 Meteor Shower(BFS)
- POJ 3669 Meteor Shower BFS
- 451. Sort Characters By Frequency
- 56.两数之和
- Python学习记录之一爬图片
- LeetCode-algorithms 413. Arithmetic Slices
- 注册功能
- poj 3669-Meteor Shower(简单bfs)
- C++基础
- eclipse导入myeclipse项目
- Leetcode——32. Longest Valid Parentheses
- weka之ID3
- VIM编辑技巧之把单词大小写转换
- 读书笔记《Effective C++》条款31:将文件间的编译依存关系降至最低
- 热键与快捷键的区别
- Java之多线程加强(多线程调度与控制)