USACO Summary: Bronze Problem # 4 (Source Code Included)

To measure traffic on a highway, detectors are used for entrance (ON), exit (OFF) and main road (MAIN). Each detector is installed on a location away from the others, and each provides a min/max range of passing vehicles. For the given input data, calculate both the starting and ending traffic for the highway.

Sample Input: input.txt

4
on 2 3
main 9 15
main 10 16
off 1 2

Sample Output: output.txt

7 13
8 14

In the above output, (7, 13) is the traffice flow range for the beginning and ( 8, 14 ) is the traffice flow range for the end of the highway.

USACO编程竞赛概要:铜级题 #4

为了测量高速公路上的车流量,感应器被分别安装在主路(MAIN)、入口(ON)和出口(OFF)。每个感应器都远离其他感应器,测量结果都是一个区间值。给定感应器的总数,以及每个感应器测量的数据,请分别计算高速公路开始和结束时的车流量区间值。

输入样例:input.txt

4
on 2 3
main 9 15
main 10 16
off 1 2

输出样例:output.txt

7 13
8 14

在上面的输出样例里,高速公路开始时的车流量区间值为 7-13, 结束时的区间值为 8-14。

Python Solution

USACO Bronze #4 - Python Solution