题目大意:
国王要走出城堡看望其子民,并且要以最短的时间访问他所有的子民,每条街道两边都有子民,国王一次只能走一边,国王只能在街道的两端或者十字路口掉头或者选择其他走向,当一条街道一边国王第一次访问时速度是20km/h,如果是再次访问速度就为50km/h,从城堡到任何街道都可达(城堡是所有街道的交点),街道都是笔直的。
现有多个测例(测例数无上限),每个测例中给出城堡的坐标以及若干各街道两端点的坐标(所有坐标都是int型整数),以单词“java”表示一个测例的输入结束,要求对于每个测例都输出国王访问完所有子民的最短时间,要求四舍五入到分钟,输出格式时“XX:XX”,其中分钟如果是一个10以内的数,则以0打头,比如"3:03”, “12::00"等。
注释代码:
/*
* Problem ID : ZOJ 1105 FatMouse's Tour
* Author : Lirx.t.Una
* Language : C
* Run Time : 0 ms
* Run Memory : 168 KB
*/
#include <stdio.h>
#include <math.h>
//street information
//表示输入信息(街道两个端点的输入信息)的长度
#define STINFO 80
#define POW(x) ( (x) * (x) )
#define DIST(x1,y1,x2,y2) sqrt(POW( (x1) - (x2) ) + POW( (y1) - (y2) ))
char st[STINFO];//street information
//由于城堡到各街道都可达,因此每条街道两边国王只需走一次就行了
//所以时间就是 总路程(街道长度之和的两倍) ÷ 20km/h
int
main() {
double x1, y1;//两端点
double x2, y2;
double dist;//两端点之间的距离
int t;//time,遍历的最短时间
while ( ~scanf("%lf%lf\n", &x1, &y1) ) {
dist = 0.0;
while ( gets(st), *st != 'j' ) {
sscanf(st, "%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
dist += DIST( x1, y1, x2, y2 );
}
t = (int)( 2.0 * dist * 60.0 / 20000.0 + 0.5 );//四舍五入
printf("%d:%02d\n", t / 60, t % 60);//注意分钟的输出格式
}
return 0;
}
无注释代码:
#include <stdio.h>
#include <math.h>
#define STINFO 80
#define POW(x) ( (x) * (x) )
#define DIST(x1,y1,x2,y2) sqrt(POW( (x1) - (x2) ) + POW( (y1) - (y2) ))
char st[STINFO];
int
main() {
double x1, y1;
double x2, y2;
double dist;
int t;
while ( ~scanf("%lf%lf\n", &x1, &y1) ) {
dist = 0.0;
while ( gets(st), *st != 'j' ) {
sscanf(st, "%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
dist += DIST( x1, y1, x2, y2 );
}
t = (int)( 2.0 * dist * 60.0 / 20000.0 + 0.5 );
printf("%d:%02d\n", t / 60, t % 60);
}
return 0;
}
单词解释:
chairman:n, 主席,会长,董事长
mice:n, 老鼠的复数
tour:n/vt, 旅游,旅行
patrol:n/vt, 巡逻