German Collegiate Programming Contest 2013:B

一个离散化的简单题;

我用的是STL来做的离散化;

好久没写离散化了,纪念一下!

代码:

German Collegiate Programming Contest 2013:BGerman Collegiate Programming Contest 2013:B
 #include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define maxn 5005
using namespace std;
vector<int>ve;
int mmb[]={,,,,,
,,,,,,};
struct node
{
int st,end;
}no[maxn]; char s[];
int lisan[maxn*]; int main()
{
int t,year,month,day,hour,min,m,n,mi;
scanf("%d",&t);
while(t--)
{
ve.clear();
scanf("%d%d",&n,&m);
for(int i=; i<n; i++)
{
scanf("%s",&s);
scanf("%d-%d-%d",&year,&month,&day);
scanf("%d:%d",&hour,&mi);
if(year==&&month>)
no[i].st=(year-)*+mmb[month-]+(day-)*+hour*+mi+;
else no[i].st=(year-)*+mmb[month-]+(day-)*+hour*+mi;
ve.push_back(no[i].st);
scanf("%d-%d-%d",&year,&month,&day);
scanf("%d:%d",&hour,&mi);
if(year==&&month>)
no[i].end=(year-)*+mmb[month-]+(day-)*+hour*+mi+m+;
else no[i].end=(year-)*+mmb[month-]+(day-)*+hour*+mi+m;
if(no[i].end==no[i].st)
ve.push_back(no[i].end+);
else ve.push_back(no[i].end);
}
sort(ve.begin(),ve.end());
ve.erase(unique(ve.begin(),ve.end()),ve.end());
memset(lisan,,sizeof lisan);
for(int i=; i<n; i++)
{
int pos=lower_bound(ve.begin(), ve.end(),no[i].st)-ve.begin();
lisan[pos]+=;
pos=lower_bound(ve.begin(), ve.end(),no[i].end)-ve.begin();
lisan[pos]+=-;
}
int mii=;
for(int i=; i<ve.size(); i++)
if(i>)
lisan[i]+=lisan[i-];
for(int i=; i<ve.size(); i++)
if(lisan[i]>mii)mii=lisan[i];
printf("%d\n",mii);
}
return ;
}
上一篇:javascript的笔记


下一篇:持续集成之 Spring Boot 实战篇