HDU 4509 湫湫系列故事——减肥记II (简单模拟)

题意:一天一共有1440分钟,主人公每天有n件事要做,给出这n件事开始跟结束的时间,然后让你求出,空闲的时间的总分钟数是多少。

解题报告:简单模拟,只要开个一维数组标记那个每个分钟是否是有事的就可以了,有事的每次输入都标记掉就可以了。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 bool flag[2000];
 8 int trans(int x,int y)
 9 {
10     return 60 * x + y;
11 }
12 
13 int main()
14 {
15     int n;
16     while(scanf("%d",&n)!=EOF)
17     {
18         memset(flag,0,sizeof(flag));
19         int sx,sy,ex,ey;
20         for(int i = 0;i < n;++i)
21         {
22             scanf("%d:%d %d:%d",&sx,&sy,&ex,&ey);
23             int t_e = trans(ex,ey);
24         //    printf("%d     %d
",trans(sx,sy),t_e);
25             for(int j = trans(sx,sy);j < t_e;++j)
26             flag[j] = 1;
27         }
28         int tot = 0;
29         for(int i = 0;i < 1440;++i)
30         tot += (!flag[i]);
31         printf("%d
",tot);
32     }
33     return 0;
34 }
View Code
原文地址:https://www.cnblogs.com/xiaxiaosheng/p/3603272.html