Description
As the Chairman of Association of Campus Mice (ACM), FatMouse is going out of his office to tour his kingdom. But with the International Cat Patrol Centers (ICPC) locating at every street, he has to carefully plan his trip so that it requires minimum time to visit everyone living at every street.
Assume that there are mice living at both sides of each street, yet FatMouse can only visit one side of a street in a single pass. He can turn any direction (including a U-turn) at any intersection, and can turn around at the end of any street. He goes at 20 km/h when visiting his people on the way (shaking hands and saying "hi"), and 50 km/h when passing a visited side of a street (since the cats must be awake by then).
Input Specification
The input file contains several test cases. Each test case starts from a line with two integers: the x,y coordinates of FatMouse's office (in metres). Up to 100 lines follow. Each gives the coordinates (in metres) of the beginning and end of a street. All streets are perfectly straight, with one side in each direction. It is possible to reach all streets from the office. Each test case is finished by a special word "java".
Output Specification
For each test case, your output should be one line with the time, in hours and minutes, required to tour the kingdom and return to the office. Round to the nearest minute.
Sample Input
0 0 0 0 10000 10000 5000 -10000 5000 10000 5000 10000 10000 10000 java
Output for Sample Input
3:55
#include<cstdio> #include<cmath> 这道题目题意要阅读清楚。每一条路都会经过两次(一来一回)。但是每条路只会访问一次(以后再不会经过这条路了)。 注意sscanf的用法,之前都没有注意到可以这样用。 using namespace std; double x[100],y[100]; double help(int n1,int n2) { return sqrt((x[n1]-x[n2])*(x[n1]-x[n2])+(y[n1]-y[n2])*(y[n1]-y[n2])); } int main() { while(scanf("%lf%lf",&x[0],&y[0])!=EOF) { char ss[1000]; double ans=0; getchar(); while(gets(ss)) { if(ss[0]=='j') break; sscanf(ss,"%lf%lf%lf%lf",&x[1],&y[1],&x[2],&y[2]); ans+=help(1,2); } ans=ans*60*2/20000; int an2=floor(ans+0.5); printf("%d:%02d\n",an2/60,an2%60); } return 0; }