Problem C: Snow Clearing
As the days become shorter and the nights become longer we turn our thoughts to snow clearing. Due to budget cuts, the Big Noisy City has exactly one snow plow. The plow can clear exactly one lane of a road in a single pass. Whenever there is snow on the ground, the plow departs from its hangar and tours the city, plowing as it goes. What is the minimum time that the plow needs to clear every lane of every road?The first line of input is the number of test cases, followed by a blank line. Then the input contains two integers: the x,y coordinates of the hangar (in metres). Up to 100 lines follow. Each gives the coordinates (in metres) of the beginning and end of a street. All roads are perfectly straight, with one lane in each direction. The plow can turn any direction (including a U-turn) at any intersection, and can turn around at the end of any street. The plow travels at 20 km/h if it is plowing, and 50 km/h if the lane it is driving on has already been plowed. It is possible to reach all streets from the hangar. There is a blank line between each consecutive test case.Your output should be the time, in hours and minutes, required to clear the streets and return to the hangar. Round to the nearest minute for each data set. Print a blank line between 2 consecutive data sets.
Sample Input
1 0 0 0 0 10000 10000 5000 -10000 5000 10000 5000 10000 10000 10000
Output for Sample Input
3:55
euler graph, 注意每條邊為雙向有兩條
#include<stdio.h>
#include<cmath>
#include<vector>
#define REP(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define DBG 0
using namespace std;
double D;
void ans(){
int a,b,c;
if(DBG)printf("D: %f\n",D);
a=int(D/20*60+0.5),b=a/60,c=a%60;
printf("%d:%02d\n",b,c);
}
double getDis(double a,double b,double c,double d){
return sqrt(pow(c-a,2)+pow(d-b,2));
}
int main(){
int x,y,n;
double a,b,c,d;
char chs[100];
bool ll=0;
scanf("%d",&n);
rep(i,n){
D=0;
scanf("%d%d ",&x,&y);
while(fgets(chs,100,stdin)){
if(chs[0]=='\n')break;
sscanf(chs,"%lf%lf%lf%lf",&a,&b,&c,&d);
a/=1000,b/=1000,c/=1000,d/=1000;
D+=2*getDis(a,b,c,d);
}
if(ll)printf("\n");ll=1;
ans();
}
}
沒有留言:
張貼留言