Test instructions: A person from home to school, walking speed 10km/h, there are subway 40km/h on the map, the subway has different lines, each line on the subway can be interconnected, two adjacent stations between the subway to run in a straight line, different metro lines can not be directly through the subway to arrive, but the different locations could be directly walking, straight line walk. To the home, school, the coordinates of the subway platform (unit m), ask how long it takes the shortest time (min) to get to the school
Pit Daddy's unit ... km/h, M, Min, then need to pay attention to the construction of subway lines need a station to build, because only the adjacent two stations to run in a straight line, but the same subway line does not necessarily build a straight line. The remaining unconnected point pairs are connected by walking, and are computed with the shortest circuit after the diagram is completed.
1#include <stdio.h>2#include <string.h>3#include <queue>4#include <vector>5#include <algorithm>6#include <math.h>7#include <map>8 using namespacestd;9typedef pair<Double,int>PII;Ten Const Doubleinf=1e9; One A structpoint{ - intx, y; - BOOL operator< (ConstPoint a)Const{ the if(x==a.x)returny<a.y; - returnx<a.x; - } -PointintAintb): X (a), Y (b) {} + }; - + intCNT; A Doublema[205][205]; at intvis[205][205]; - Doubled[205]; - intline[205],x[205],y[205]; - intcl; - - structcmp{ in BOOL operator() (PII a,pii b) { - returnA.first>B.first; to } + }; - the DoubleCalintAintb) { * returnsqrt1.0* (X[a]-x[b]) * (X[a]-x[b]) +1.0* (Y[a]-y[b]) * (y[a]-y[b])); $ }Panax Notoginseng - voidDij () { the inti; +Priority_queue<pii,vector<pii>,cmp>Q; AQ.push (Make_pair (0,1)); the for(i=1; i<=cnt;++i) d[i]=INF; +d[1]=0; - while(!Q.empty ()) { $PII u=q.top (); $ Q.pop (); - if(U.first>d[u.second])Continue; - if(u.second==2) {printf ("%d\n",(int) (d[2]/60.0+0.5)); Break;} the for(intj=2; j<=cnt;++j) { - if(J==u.second)Continue;Wuyi Doublev=Ma[u.second][j]; the if(d[j]>u.first+v) { -d[j]=u.first+v; Wu Q.push (Make_pair (d[j],j)); - } About } $ } - } - - intMain () { ACnt=0; +scanf"%d%d", &x[1],&y[1]); thescanf"%d%d", &x[2],&y[2]); -Map<point,int>m; $M[point (x[1],y[1])]=++CNT; theM[point (x[2],y[2])]=++CNT; the intx1,y1; theCl=0; the while(SCANF ("%d%d", &x1,&y1)! =EOF) { - if(x1==-1&&y1==-1){ in for(intI=2; i<=cl;++i) { the intj=i-1; theMa[line[j]][line[i]]=ma[line[i]][line[j]]=cal (Line[i],line[j])/40.0*3.6; Aboutvis[line[i]][line[j]]=vis[line[j]][line[i]]=1; the } theCl=0; the } + Else{ - Point tmp (X1,Y1); the if(M[tmp]) line[++cl]=m[tmp];Bayi Else{ theline[++cl]=m[tmp]=++CNT; thex[cnt]=x1;y[cnt]=Y1; - } - } the } the for(intI=1; i<=cnt;++i) { the for(intj=i+1; j<=cnt;++j) { the if(!vis[i][j]) ma[i][j]=ma[j][i]=cal (I,J)/10.0*3.6; - } the } the Dij (); the return 0;94}
View Code
poj2502 Shortest circuit