hdu 4509(memset标记)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4509

memset标记,挺不错的方法。。

View Code
 1 #include<iostream>
 2 #include<cstring>
 3 using namespace std;
 4 
 5 
 6 int main(){
 7     int n;
 8     while(~scanf("%d",&n)){
 9         int time[1440];
10         int sh,eh,sm,em;
11         memset(time,1,sizeof(time));//一开始全部用1标记
12         for(int i=1;i<=n;i++){
13             scanf("%d:%d %d:%d",&sh,&sm,&eh,&em);
14             int s=sh*60+sm;
15             int e=eh*60+em;
16             memset(time+s,0,(e-s)*sizeof(time[0]));//做事的一段时间全部用0标记
17         }
18         int count=0;
19         for(int i=0;i<1440;i++)if(time[i]){
20             count++;
21         }
22         printf("%d\n",count);
23     }
24     return 0;
25 }

 

 

posted @ 2013-03-22 15:01  ihge2k  阅读(166)  评论(0编辑  收藏  举报