题目链接:点击打开链接
由于只有24*60个时间点,所以根据每个group来到和离开的时间增加这些时间点的同时最大人数,最后遍历这1440个点即可
由于一个团队离开的时刻另一个团队可以马上坐他们的位置,所以一个团队在饭店中的时间实际上是离开时间的前一个时间点
所以for(int j=time(G[i].sh,G[i].sm);j<time(G[i].eh,G[i].em);j++) 后面要写小于号
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
struct group{
int sh,sm;
int eh,em,n;
}G[10010];
int tt[2000];
int time(int a,int b){
return a*60+b;
}
bool cmp(group a,group b){
return (a.sh*60+a.sm)<(b.sh*60+b.sm);
}
int main()
{
int T;
cin>>T;
while(T--){
memset(tt,0,sizeof(tt));
int num;
int nowt=0;
int tot=0;
cin>>num;
for(int i=1;i<=num;i++){
char time[100];
int n;
cin>>G[i].n>>time;
char tmp;
sscanf(time,"%d%c%d",&G[i].sh,&tmp,&G[i].sm);
cin>>time;
sscanf(time,"%d%c%d",&G[i].eh,&tmp,&G[i].em);
}
for(int i=1;i<=num;i++){
for(int j=time(G[i].sh,G[i].sm);j<time(G[i].eh,G[i].em);j++){
tt[j]+=G[i].n;
}
if(
}
for(int i=0;i<=1500;i++){
tot=max(tot,tt[i]);
}
cout<<tot<<endl;
}
return 0;
}