POJ 2502 subway 演算法的问题DescriptionYou have just moved from a quiet Waterloo neighbourhood to a big,noisy city.Instead of getting to ride your bike to school every day,you now get to walk and takethe subway.Because you don't want to be late

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/24 19:51:51
POJ 2502 subway 演算法的问题DescriptionYou have just moved from a quiet Waterloo neighbourhood to a big,noisy city.Instead of getting to ride your bike to school every day,you now get to walk and takethe subway.Because you don't want to be late
xW[5+~if'Byɶ"Qi*x2NfdTBHCoJTUPC˯[ǷIfrMO}w|%q=:xy齃wz}__ IGЁ}Szi"QwcѵbID9bv6OEȹ$6VI:TfG,K @D$0!CD|Ua1>TZj}> >!xNm %Ai6AĹ&0& $(u"$ڮ[+!GR(^9&!:ëҏki%'IC!Lm 5r1`!(Pb|Ċ*V)C4kDm69>qL| HDʋ3 *42Ҹ !+Ic\J;R `9$!\2 `4 ka2V}*HGeg@T$UsZ)<-:JAeTJ\AzZ\cSB6'a<lg hGuE.]Č[qHLIdgDG1,V#"b\z j(gM'C(G{Pжd H03)\~uuGArȍ}/gɍR5; Ox4TFu.8r_Mz}9BB+.(i#e‚B'Y'MKuOm )Z%IT`h ES?-sg/< Oi;ϼL|frJGy2'|T?36;9,88^1/Md 6%¦dbѨ\Y<֝<ղ 2,6&C/&dh֜U? &r0{<;fbУʖnW,Ɋ+Iz/:]#5ЖQ[nj^ۂ #NgqedhVA'=VqɌfPoRx[Nۇ+lVR٘e.ʧgMz:Mlҵ;S-RӡC۴k^o4wSs6[%SzP121Y)-#k /]k|~XZouo=ݛ HcTS#i,mwكH ;8'>ND#Hp+V>JxRF|M^1K・kny#胁|lm(jV6oDQ}dޙrٻ|{9S) S5&mZd9A

POJ 2502 subway 演算法的问题DescriptionYou have just moved from a quiet Waterloo neighbourhood to a big,noisy city.Instead of getting to ride your bike to school every day,you now get to walk and takethe subway.Because you don't want to be late
POJ 2502 subway 演算法的问题
Description
You have just moved from a quiet Waterloo neighbourhood to a big,noisy city.
Instead of getting to ride your bike to school every day,you now get to walk and take
the subway.Because you don't want to be late for class,you want to know how long it
will take you to get to school.
You walk at a speed of W (km/h).The subway travels at S (km/h).Assume that you
are lucky,and whenever you arrive at a subway station,a train is there that you can
board immediately.You may get on and off the subway any number of times,and you
may switch between different subway lines if you wish.All subway lines go in both
directions.
Input
The first input line are W and S.Input consists of the x,y coordinates of your home
and your school,followed by specifications of several subway lines.Each subway line
consists of the non-negative integer x,y coordinates of each stop on the line,in order.
You may assume the subway runs in a straight line between adjacent stops,and the
coordinates represent an integral number of metres.Each line has at least two stops.
The end of each subway line is followed by the dummy coordinate pair -1,-1.In total
there are at most 200 subway stops in the city.
Output
The first line is the number of minutes it will take you to get to school,rounded to
the nearest minute,taking the fastest route.Then print the fastest route.
-------------------------------
想请问此题目的程式码要如何作答?
不是C++作答喔

POJ 2502 subway 演算法的问题DescriptionYou have just moved from a quiet Waterloo neighbourhood to a big,noisy city.Instead of getting to ride your bike to school every day,you now get to walk and takethe subway.Because you don't want to be late
最短路径算法,Dijkstra或者Floyd
Java你不会自己写吗.
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{

\x05public static double cal(int x, int y, int nx, int ny, int speed) {
\x05\x05int dx = x - nx;
\x05\x05int dy = y - ny;
\x05\x05return 1.0 * Math.sqrt(dx*dx + dy*dy) / speed;
\x05}
\x05public static void main (String[] args) throws java.lang.Exception
\x05{
\x05\x05// your code goes here
\x05\x05Scanner cin = new Scanner(System.in);
\x05\x05int[] x = new int[300];
\x05\x05int[] y = new int[300];
\x05\x05double[][] dist = new double[300][300];
\x05\x05for(int i=0;i<300;i++) {
\x05\x05\x05for(int j=0;j<300;j++) {
\x05\x05\x05\x05dist[i][j] = -1;
\x05\x05\x05}
\x05\x05}
\x05\x05int num = 2;
\x05\x05x[0] = cin.nextInt();
\x05\x05y[0] = cin.nextInt();
\x05\x05x[1] = cin.nextInt();
\x05\x05y[1] = cin.nextInt();
\x05\x05while(cin.hasNextInt()) {
\x05\x05\x05int fx, fy, nx, ny;
\x05\x05\x05fx = cin.nextInt();
\x05\x05\x05fy = cin.nextInt();
\x05\x05\x05x[num] = fx;
\x05\x05\x05y[num] = fy;
\x05\x05\x05num = num + 1;
\x05\x05\x05do {
\x05\x05\x05\x05nx = cin.nextInt();
\x05\x05\x05\x05ny = cin.nextInt();
\x05\x05\x05\x05if(nx == -1 && ny == -1) break;
\x05\x05\x05\x05x[num] = nx;
\x05\x05\x05\x05y[num] = ny;
\x05\x05\x05\x05num = num + 1;
\x05\x05\x05\x05dist[num-1][num-2] = dist[num-2][num-1] = cal(x[num-2],y[num-2],x[num-1],y[num-1],40000);
\x05\x05\x05\x05fx = nx;
\x05\x05\x05\x05fy = ny;
\x05\x05\x05}while(true);
\x05\x05}
\x05\x05for(int i=0;i<num;i++) {
\x05\x05\x05dist[i][i] = 0;
\x05\x05\x05for(int j=i+1;j<num;j++) {
\x05\x05\x05\x05if(dist[i][j] < 0) {
\x05\x05\x05\x05\x05dist[i][j] = dist[j][i] = cal(x[i],y[i],x[j],y[j],10000);
\x05\x05\x05\x05}
\x05\x05\x05}
\x05\x05}
\x05\x05for(int k=0;k<num;k++) {
\x05\x05\x05for(int i=0;i<num;i++) {
\x05\x05\x05\x05for(int j=0;j<num;j++) {
\x05\x05\x05\x05\x05if(dist[i][j] > dist[i][k] + dist[k][j]) {
\x05\x05\x05\x05\x05\x05dist[i][j] = dist[i][k] + dist[k][j];
\x05\x05\x05\x05\x05}
\x05\x05\x05\x05}
\x05\x05\x05}
\x05\x05}
\x05\x05double ans = dist[0][1] * 60;
\x05\x05int ansint = (int)Math.floor(ans + 0.5);
\x05\x05System.out.printf("%d%n",ansint);
\x05}
}