题目
一个人在等车,已知当前的时间,和每辆公交车的开车时间和他到家需要的时间,问他最早什么时间到家。
分析
暴力模拟。枚举所有的车找到最早到家的即可。
说明
如果当前时间晚于发车时间,可以等明天的车。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int T, K, H, M, L;
while (~scanf("%d", &T))
for (int t = 1; t <= T; ++ t) {
scanf("%d %d:%d", &K, &H, &M);
int now = H * 60 + M, end = 10000;
for (int i = 1; i <= K; ++ i) {
scanf("%d:%d %d", &H, &M, &L);
// if miss the bus he only can take it in the next day.
if (H * 60 + M < now) {
H += 24;
}
if (end > H * 60 + M + L) {
end = H * 60 + M + L;
}
}
printf("Case %d: %d\n", t, end - now);
}
return 0;
}