zoj 3787 Access System
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5274
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 int n,l; 7 char str[100]; 8 int ans[100000]; 9 struct node 10 { 11 int h,m,s; 12 int id; 13 bool operator <(const node &a)const 14 { 15 return (h<a.h)||(h==a.h&&m<a.m)||(h==a.h&&m==a.m&&s<a.s); 16 } 17 }p[200020]; 18 19 int main() 20 { 21 int t; 22 scanf("%d",&t); 23 while(t--) 24 { 25 scanf("%d%d",&n,&l); 26 for(int i=0; i<n; i++) 27 { 28 scanf("%s",str); 29 p[i].h=(str[0]-'0')*10+(str[1]-'0'); 30 p[i].m=(str[3]-'0')*10+(str[4]-'0'); 31 p[i].s=(str[6]-'0')*10+(str[7]-'0'); 32 p[i].id=i+1; 33 } 34 sort(p,p+n); 35 int t1=0; 36 node pos; 37 /*for(int i=0; i<n; i++) 38 { 39 printf("%d %d %d\n",p[i].h,p[i].m,p[i].s); 40 }*/ 41 for(int i=0; i<n; i++) 42 { 43 if(i==0) 44 { 45 ans[t1++]=p[i].id; 46 pos.s=(p[i].s+l)%60; 47 pos.m=(p[i].m+(p[i].s+l)/60)%60; 48 pos.h=p[i].h+((p[i].m+(p[i].s+l)/60)/60); 49 } 50 else 51 { 52 //printf("%d %d %d\n",pos.h,pos.m,pos.s); 53 if(p[i].h>pos.h) 54 { 55 ans[t1++]=p[i].id; 56 pos.s=(p[i].s+l)%60; 57 pos.m=(p[i].m+(p[i].s+l)/60)%60; 58 pos.h=p[i].h+((p[i].m+(p[i].s+l)/60)/60); 59 } 60 else if(p[i].h==pos.h&&p[i].m>pos.m) 61 { 62 ans[t1++]=p[i].id; 63 pos.s=(p[i].s+l)%60; 64 pos.m=(p[i].m+(p[i].s+l)/60)%60; 65 pos.h=p[i].h+((p[i].m+(p[i].s+l)/60)/60); 66 } 67 else if(p[i].h==pos.h&&p[i].m==pos.m&&p[i].s>pos.s) 68 { 69 ans[t1++]=p[i].id; 70 pos.s=(p[i].s+l)%60; 71 pos.m=(p[i].m+(p[i].s+l)/60)%60; 72 pos.h=p[i].h+((p[i].m+(p[i].s+l)/60)/60); 73 } 74 else if(p[i].h==pos.h&&p[i].m==pos.m&&p[i].s==pos.s) 75 { 76 ans[t1++]=p[i].id; 77 pos.s=(p[i].s+l)%60; 78 pos.m=(p[i].m+(p[i].s+l)/60)%60; 79 pos.h=p[i].h+((p[i].m+(p[i].s+l)/60)/60); 80 } 81 } 82 } 83 printf("%d\n",t1); 84 sort(ans,ans+t1); 85 for(int i=0; i<t1; i++) 86 { 87 if(i==0) 88 { 89 printf("%d",ans[i]); 90 } 91 else 92 { 93 printf(" %d",ans[i]); 94 } 95 } 96 printf("\n"); 97 } 98 return 0; 99 }