GCPC 2013 B(模拟+贪心+时间转换)

题意:给出宾馆房间的入住时间离开时间,和打扫时间,在一间房间入住之前应该打扫一次。求最少需要多少个房间。

思路:首先数据量是2013年到2016年,把时间转换成分钟(以2013年1月1日为起点),结束时间加上打扫时间,在一个数组中对入住对应的时间++表示这个点住了,对离开时间--表示这个点离开了,可以看出答案就是时间从0到maxn的入住和离开的人数的代数和的最大值。

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int maxn=3000000;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
int p[maxn];
int mon[]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
int get(int y,int m,int d,int h,int f)
{
    int sum=0,t=0;
    if(y != 2016) mon[2]=28;
    else mon[2]=29;
    d+=(y - 2013)*365;
    for(int i=0; i<m; i++)
        d+=mon[i];
    return (d*24*60+h*60+f);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        memset(p,0,sizeof(p));
        int n,c;
        cin>>n>>c;
        char s[25];
        int y,m,d,h,f;
        //   1 2013-07-01 15:59 2013-07-08 16:30
        for(int i=0; i<n; i++)
        {
            scanf("%s %d-%d-%d %d:%d",s,&y,&m,&d,&h,&f);
            int a=get(y,m,d,h,f);
            p[a]++;
            scanf("%d-%d-%d %d:%d",&y,&m,&d,&h,&f);
            int b=get(y,m,d,h,f)+c;
            p[b]--;
        }
        int ans=p[0];
        for(int i=1; i<maxn; i++)
        {
            p[i]+=p[i-1];
            ans=max(p[i],ans);
        }
        cout<<ans<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Dilly__dally/article/details/82431041