German Collegiate Programming Contest 2013:B
一个离散化的简单题;
我用的是STL来做的离散化;
好久没写离散化了,纪念一下!
代码:
1 #include<cstdio> 2 #include<cstring> 3 #include<vector> 4 #include<algorithm> 5 #define maxn 5005 6 using namespace std; 7 vector<int>ve; 8 int mmb[12]={0,44640,84960,129600,172800, 9 217440,260640,305280,349920,393120,437760,480960}; 10 struct node 11 { 12 int st,end; 13 }no[maxn]; 14 15 char s[10]; 16 int lisan[maxn*2]; 17 18 int main() 19 { 20 int t,year,month,day,hour,min,m,n,mi; 21 scanf("%d",&t); 22 while(t--) 23 { 24 ve.clear(); 25 scanf("%d%d",&n,&m); 26 for(int i=0; i<n; i++) 27 { 28 scanf("%s",&s); 29 scanf("%d-%d-%d",&year,&month,&day); 30 scanf("%d:%d",&hour,&mi); 31 if(year==2016&&month>2) 32 no[i].st=(year-2013)*525600+mmb[month-1]+(day-1)*1440+hour*60+mi+1440; 33 else no[i].st=(year-2013)*525600+mmb[month-1]+(day-1)*1440+hour*60+mi; 34 ve.push_back(no[i].st); 35 scanf("%d-%d-%d",&year,&month,&day); 36 scanf("%d:%d",&hour,&mi); 37 if(year==2016&&month>2) 38 no[i].end=(year-2013)*525600+mmb[month-1]+(day-1)*1440+hour*60+mi+m+1440; 39 else no[i].end=(year-2013)*525600+mmb[month-1]+(day-1)*1440+hour*60+mi+m; 40 if(no[i].end==no[i].st) 41 ve.push_back(no[i].end+1); 42 else ve.push_back(no[i].end); 43 } 44 sort(ve.begin(),ve.end()); 45 ve.erase(unique(ve.begin(),ve.end()),ve.end()); 46 memset(lisan,0,sizeof lisan); 47 for(int i=0; i<n; i++) 48 { 49 int pos=lower_bound(ve.begin(), ve.end(),no[i].st)-ve.begin(); 50 lisan[pos]+=1; 51 pos=lower_bound(ve.begin(), ve.end(),no[i].end)-ve.begin(); 52 lisan[pos]+=-1; 53 } 54 int mii=0; 55 for(int i=0; i<ve.size(); i++) 56 if(i>0) 57 lisan[i]+=lisan[i-1]; 58 for(int i=0; i<ve.size(); i++) 59 if(lisan[i]>mii)mii=lisan[i]; 60 printf("%d\n",mii); 61 } 62 return 0; 63 }