Aizu 1315 Gift from the Goddess of Programming 解题报告

来源:互联网 发布:适用于mac的办公软件 编辑:程序博客网 时间:2024/05/21 17:34

题目

题意:

一群ACMer去祭坛祈祷,其中在God在的时候祈祷总时长最长的人会被选中……现在告诉你所有人的出入记录,并且God的编号为0,求最长的总时长。

读了好几遍,不知道是不是必须当天离开,也不知道是否保证最后全部人都会离开。

题解:

以保万一,写得很麻烦,但我觉得忽略日期是可以的。 


//Memory:1220KB
//Length:1193B#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <map>using namespace std;#define MAXN 1010#define INF 1000000007map<int,int> ma;int pre[MAXN],sum[MAXN];int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};int gettime(){    int m,d,h,t;    scanf("%d/%d %d:%d",&m,&d,&h,&t);    return ((mon[m-1]+d)*24+h)*60+t;}int main(){    //freopen("/home/moor/Code/input","r",stdin);    int n,now,ans;    while(scanf("%d",&n)&&n)    {        now=1;        ma.clear();        ma[0]=0;        memset(pre,0x3f,sizeof(pre));        memset(sum,0,sizeof(sum));        for(int i=0;i<n;++i)        {            char s[2];            int t,p;            t=gettime(),scanf("%s%d",s,&p);            if(ma.find(p)==ma.end())    ma[p]=now++;            p=ma[p];            if(s[0]=='I')   pre[p]=t;            else            {                if(p==0)                    for(int j=1;j<now;++j)  sum[j]+=max(0,t-max(pre[0],pre[j]));                else    sum[p]+=max(0,t-max(pre[0],pre[p]));                pre[p]=INF;            }        }        ans=0;        for(int i=1;i<now;++i)  ans=max(ans,sum[i]);        printf("%d\n",ans);    }}


原创粉丝点击