John is going back home after a party. Currently he is standing on a bus station and waiting for a bus to arrive. There is a timetable of arriving buses near the station. Beside this, John also knows the amount of time that is needed to travel with specific bus. As he has only one ticket, there are no possibilities to change the bus somewhere in the middle of a trip in order to make it shorter. Can you help John to calculate minimal time that he needs to get home?
Input
There is a number of tests T (T ≤ 100) on the first line. Each test case contains the number of buses K (1 ≤ K ≤ 100) and current time (in format ‘HH:MM’. Each of the next K lines contain arrival time of the bus (in the same format as current time) and travelling time 0 ≤ Q ≤ 1000 needed for John to get home (in minutes). Refer to the sample input as an example.
Output
For each test case output a single line ‘Case T: N’. Where T is the test case number (starting from 1) and N minimal time (in minutes) needed for John to go back home.
Sample Input
2
1 18:00
19:30 30
2 18:00
19:00 100
20:00 30
Sample Output
Case 1: 120
Case 2: 150
问题链接:UVA11958 Coming Home
问题简述:(略)
问题分析:
计算回家时间问题。
简单题,给出代码,暂时不解释。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA11958 Coming Home */
#include <bits/stdc++.h>
using namespace std;
const int D = 24;
const int H = 60;
int main()
{
int t, caseno = 0, k, h, m, l;
scanf("%d", &t);
while(t--) {
scanf("%d%d:%d", &k, &h, &m);
int start = h * H + m, end = 10000;
for(int i = 1; i <= k; i++) {
scanf("%d:%d%d", &h, &m, &l);
if(h * H + m < start) h += D; // 当天没坐上车
int e = h * H + m + l;
if(e < end) end = e;
}
printf("Case %d: %d\n", ++caseno, end - start);
}
return 0;
}