做BC CF TC 这种东西 做一次 Rating掉一次。。。
hdu 4883 TIANKENG's restaurant
题目大意就是一群人分成几拨去餐厅吃饭 餐厅安排凳子 如果后面去的人去的时候前面的人已经离开就是可以使用之前使用的凳子 如果有重叠的就要另外安排了
看到这个题的第一想法是会场安排问题 一个简单的贪心就可以了 然后很快写完第一发跪了。。
后来发现我这种写法容易出现很多问题 他那个重叠的情况比较复杂 然后来了一发暴力 TLE
然后搞了老半天 这题还是没做出来 简直蛋疼。。。
后来ACgege梁平君发了个代码。。他的想法就是将所有时间排序 然后对时间遍历 进来的时间就将人数相加 出去的时间就将人数相减 直到取得最大值
这么基础的题。。。来个代码
那个比较程序 如果时间相同就按数量排序
<span style="font-family:KaiTi_GB2312;font-size:18px;">#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstring>
#define N 100010
using namespace std;
struct P
{
int time,num;
bool operator<(const P& a)const
{
if(time!=a.time) return time<a.time;
return num<a.num;
}
};
P p[N*2];
int main()
{
//freopen("ceshi.txt","r",stdin);
int tc;
scanf("%d",&tc);
while(tc--)
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
int cnt,hh,mm;
scanf("%d",&cnt);
p[i*2].num=cnt;
p[i*2+1].num=-cnt;
scanf("%d:%d",&hh,&mm);
p[i*2].time=hh*60+mm;
scanf("%d:%d",&hh,&mm);
p[i*2+1].time=hh*60+mm;
}
sort(p,p+n*2);
int ans=0,maxn=0;
for(int i=0;i<n*2;i++)
{
ans+=p[i].num;
maxn=maxn>ans?maxn:ans;
}
printf("%d\n",maxn);
}
return 0;
}</span>