Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6979 | Accepted: 2287 |
Description
Input
Output
Sample Input
0 0 10000 1000 0 200 5000 200 7000 200 -1 -1 2000 600 5000 600 10000 600 -1 -1
Sample Output
21
Source
#include<cstdio> #include<string> #include<iostream> #include<cstring> #include<cmath> #include<stack> #include<queue> #include<map> #include<stdlib.h> #include<algorithm> #define LL __int64 using namespace std; const int MAXN=300+5; const double INF=0x3f3f3f3f ; struct node { double x,y; }po[MAXN]; double w[MAXN][MAXN],d[MAXN]; int vis[MAXN]; int tot; double calc(node A,node B) { return sqrt( (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y) ); } void dij() { // memset(vis,0,sizeof(vis)); // memset(d,INF,sizeof(INF)) for(int i=1;i<=tot;i++) { vis[i]=0; d[i]=INF; } d[1]=0; for(int i=1;i<=tot;i++) { int tmp; double minn=INF; for(int j=1;j<=tot;j++) { if(!vis[j] && d[j]<minn) { minn=d[j]; tmp=j; } } vis[tmp]=1; for(int j=1;j<=tot;j++) if(d[tmp]+w[tmp][j]<d[j]) d[j]=d[tmp]+w[tmp][j]; } } int main() { //freopen("in.txt","r",stdin); scanf("%lf %lf %lf %lf",&po[1].x,&po[1].y,&po[2].x,&po[2].y); for(int i=1;i<=MAXN;i++) for(int j=1;j<=MAXN;j++) { if(i==j) w[i][j]=0; else w[i][j]=INF; } bool flag=false; double x,y; tot=3; while(scanf("%lf %lf",&x,&y)==2) { if(x==-1 && y==-1) { flag=false; continue; } po[tot].x=x; po[tot].y=y; if(flag && calc(po[tot-1],po[tot])/40000.0<w[tot][tot-1]) w[tot][tot-1]=w[tot-1][tot]=calc(po[tot-1],po[tot])/40000.0; tot++; flag=true; } for(int i=1;i<=tot;i++) for(int j=1;j<=tot;j++) if(i!=j && w[i][j]==INF) w[i][j]=calc(po[i],po[j])/10000.0; dij(); printf("%d\n",(int)(d[2]*60+0.5)); return 0; }