24h購物| | PChome| 登入
2014-02-17 08:55:07| 人氣4,411| 回應0 | 上一篇 | 下一篇

[UVA][歐拉迴路] 10203 - Snow Clearing

推薦 0 收藏 0 轉貼0 訂閱站台

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

題目已經偷偷地透露要經過所有邊,且回到一開始出發的地方,求最少花費時間。

但題目又偷偷表示,每一條道路都有兩個方向。

在有向圖中,歐拉迴路符合所有點的入度等於出度,因此直接計算所有道路的長度即可。


#include <stdio.h>
#include <math.h>
int main() {
    int testcase;
    char s[1024];
    scanf("%d", &testcase);
    while(getchar() != '\n');
    while(getchar() != '\n');
    while(testcase--) {
        gets(s);
        double x1, y1, x2, y2;
        double dist = 0;
        while(gets(s) && s[0] != '\0') {
            sscanf(s, "%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
            dist += hypot(x1 - x2, y1 - y2);
        }
        dist = dist / 1000; // km
        double hh = dist * 2 / 20; // * 2 (with one lane in each direction)
        int mm = (int)round(hh * 60);
        printf("%d:%02d\n", mm/60, mm%60);
        if(testcase)
            puts("");
    }
    return 0;
}

台長: Morris
人氣(4,411) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: UVA |
此分類下一篇:[UVA][概率] 10217 - A Dinner with Schwarzenegger
此分類上一篇:[UVA][floyd] 10246 - Asterix and Obelix

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文