题意:一天一共有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\n",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\n",tot);
32     }
33     return 0;
34 }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-19
  • 2021-06-02
  • 2021-12-14
  • 2022-02-26
  • 2021-06-08
  • 2021-12-14
猜你喜欢
  • 2021-08-15
  • 2022-12-23
  • 2022-03-02
  • 2021-05-17
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
相关资源
相似解决方案