ZOJ 1105 FatMouse's Tour

来源:互联网 发布:cms建站 手机与pc 编辑:程序博客网 时间:2024/04/30 03:59

题目大意:

        国王要走出城堡看望其子民,并且要以最短的时间访问他所有的子民,每条街道两边都有子民,国王一次只能走一边,国王只能在街道的两端或者十字路口掉头或者选择其他走向,当一条街道一边国王第一次访问时速度是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//表示输入信息(街道两个端点的输入信息)的长度#defineSTINFO80#definePOW(x)( (x) * (x) )#defineDIST(x1,y1,x2,y2)sqrt(POW( (x1) - (x2) ) + POW( (y1) - (y2) ))charst[STINFO];//street information//由于城堡到各街道都可达,因此每条街道两边国王只需走一次就行了//所以时间就是  总路程(街道长度之和的两倍) ÷ 20km/hintmain() {doublex1, y1;//两端点doublex2, y2;doubledist;//两端点之间的距离intt;//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>#defineSTINFO80#definePOW(x)( (x) * (x) )#defineDIST(x1,y1,x2,y2)sqrt(POW( (x1) - (x2) ) + POW( (y1) - (y2) ))charst[STINFO];intmain() {doublex1, y1;doublex2, y2;doubledist;intt;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, 巡逻

0 0
原创粉丝点击