标签:
题意:在一个二维平面中 一个人走路的速度是 5m/s , 平面中有n个大炮,射程固定为50m且时间为2秒 ,问你最短时间。
解题思路:最短路
解题代码:
1 // File Name: e.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月14日 星期六 16时47分54秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque> 10 #include<stack> 11 #include<bitset> 12 #include<algorithm> 13 #include<functional> 14 #include<numeric> 15 #include<utility> 16 #include<sstream> 17 #include<iostream> 18 #include<iomanip> 19 #include<cstdio> 20 #include<cmath> 21 #include<cstdlib> 22 #include<cstring> 23 #include<ctime> 24 #define LL long long 25 26 using namespace std; 27 double mp[200][200]; 28 struct node{ 29 double x, y; 30 }dapao[200],be,en ; 31 int n; 32 double dis(double x1,double x2,double y1,double y2) 33 { 34 return sqrt((x1-y1)*(x1-y1) + (x2-y2)*(x2-y2)); 35 } 36 double mi ; 37 int main(){ 38 scanf("%lf %lf",&be.x,&be.y); 39 scanf("%lf %lf",&en.x,&en.y); 40 41 mi = dis(be.x,be.y,en.x,en.y)/5; 42 scanf("%d",&n); 43 44 dapao[n+1].x = en.x ; 45 dapao[n+1].y = en.y ; 46 for(int i = 1;i <= n;i ++) 47 { 48 scanf("%lf %lf",&dapao[i].x,&dapao[i].y) ; 49 } 50 for(int i= 1;i <= n;i ++) 51 { 52 for(int j = 1;j <= n+1 ; j ++) 53 { 54 double tmp; 55 mp[i][j] = dis(dapao[i].x,dapao[i].y,dapao[j].x,dapao[j].y); 56 tmp = 2 + fabs(50.0 - mp[i][j])/5 ; 57 mp[i][j] = min(mp[i][j]/5,tmp); 58 } 59 } 60 for(int k= 1;k <= n;k ++) 61 { 62 for(int i = 1;i <= n;i ++) 63 { 64 for(int j =1 ;j <= n + 1;j ++) 65 mp[i][j] = min(mp[i][j],mp[i][k] + mp[k][j]); 66 } 67 } 68 for(int i = 1;i <= n;i ++) 69 { 70 mi = min(mi,dis(be.x,be.y,dapao[i].x,dapao[i].y)/5+mp[i][n+1]); 71 } 72 printf("%f\n",mi); 73 return 0; 74 }
ACM-ICPC North America Qualifier 2014 Human Cannonball Run
标签:
原文地址:http://www.cnblogs.com/zyue/p/4338243.html