标签:
poj2627
题意:知道起点和终点,同时知道飞行速度和能在外面飞行的最长时间,问最小经过多少个洞可以到达终点
分析:裸的bfs
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <vector> 6 #include <algorithm> 7 #include <set> 8 #include <map> 9 #include <bitset> 10 #include <cmath> 11 #include <queue> 12 #include <stack> 13 using namespace std; 14 const int maxn=2020; 15 typedef struct P 16 { 17 double x,y; 18 int rec; 19 bool vis; 20 }P; 21 P p[maxn]; 22 double sx,sy,gx,gy; 23 double distance(double x1,double y1,double x2,double y2) 24 { 25 return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); 26 } 27 double v,m; 28 int main() 29 { 30 cin>>v>>m; 31 cin>>sx>>sy>>gx>>gy; 32 int h=1; 33 while(cin>>p[h].x>>p[h].y) 34 { 35 p[h].rec=0; 36 p[h].vis=false; 37 h++; 38 } 39 double dist=v*m*60; 40 if(distance(sx,sy,gx,gy)<=dist) 41 { 42 cout<<"Yes, visiting 0 other holes."<<endl; 43 return 0; 44 } 45 P s; 46 queue<P> que; 47 s.x=sx,s.y=sy,s.rec=0,s.vis=true; 48 que.push(s); 49 int ans=0x3ffff; 50 int flag=0; 51 while(!que.empty()) 52 { 53 P t=que.front(); 54 que.pop(); 55 if(distance(t.x,t.y,gx,gy)<=dist) 56 { 57 flag=1; 58 ans=min(ans,t.rec); 59 } 60 for(int i=1;i<h;i++) 61 { 62 if(distance(t.x,t.y,p[i].x,p[i].y)>dist||p[i].vis==true) 63 continue; 64 p[i].rec=t.rec+1; 65 p[i].vis=true; 66 que.push(p[i]); 67 } 68 } 69 if(flag) 70 cout<<"Yes, visiting "<<ans<<" other holes."<<endl; 71 else 72 cout<<"No. "<<endl; 73 return 0; 74 }
标签:
原文地址:http://www.cnblogs.com/wolf940509/p/5352196.html