现在的位置: 首页 > 综合 > 正文

csu 1458: Booking (开的房间数量)

2018年02月21日 ⁄ 综合 ⁄ 共 1750字 ⁄ 字号 评论关闭

1458: Booking

Time Limit: 3 Sec Memory Limit:
128 MB
Submit: 116 Solved: 27
[Submit][Status][Web
Board
]

Description

Input

Output

Sample Input

4
2 120
1 2013-07-01 15:59 2013-07-08 16:30
2 2013-07-08 17:30 2013-07-15 12:00
3 60
65 2013-07-08 14:30 2013-07-08 16:00
32 2013-07-01 16:00 2013-07-15 12:00
91 2013-07-01 16:00 2013-07-08 15:00
2 360
a7 2016-02-21 14:00 2016-02-28 21:00
xx 2016-03-01 01:00 2016-03-02 12:57
2 60
a9 2016-02-21 14:00 2016-02-28 11:00
a8 2016-02-28 12:00 2016-03-11 21:00

Sample Output

2
3
1
1
题意:开房的预定时间和离开时间,下一个要重新开一间那么这次预定时间必须要在前面开房的离开时+打扫时间之内。
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef struct nnn
{
    int st;
    int et;
}node;
node book[5005];
int cmp(node a,node b)
{
    if(a.st==b.st)
    return a.et<b.et;
    return a.st<b.st;
}
int Fun(int a,int b)
{
    if(a<=b)
    return 0;
    return 1;
}
int main()
{
    int i,i1,j,t,c,b,ans,sy,ey,sm,em,sd,ed,sh,eh;
    int d[14]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    char str[30];
    scanf("%d",&t);
    while(t--)
    {
        ans=1;
        scanf("%d%d",&b,&c);
        for(i=0;i<b;i++)
          {
              scanf("%s",str);
             scanf("%d-%d-%d %d:%d %d-%d-%d %d:%d",&sy,&sm,&sd,&sh,&book[i].st,&ey, &em,&ed, &eh, &book[i].et);
             book[i].st+=(sh*60+(sd-1)*24*60);
             for(i1=2013;i1<=sy; i1++)
             if(i1<sy)
             {
                 book[i].st+=(365*24*60);
                 if(i1%400==0||i1%4==0&&i1%100!=0)
                 book[i].st+=(24*60);
             }
             else
             {
                  if((i1%400==0||i1%4==0&&i1%100!=0)&&2<sm)
                  book[i].st+=(24*60);
                  for(j=1;j<sm; j++)
                  book[i].st+=(d[j]*60*24);
             }
             book[i].et+=(eh*60+c+(ed-1)*24*60);
             for( i1=2013;i1<=ey; i1++)
             if(i1<ey)
             {
                 book[i].et+=(365*24*60);
                 if(i1%400==0||i1%4==0&&i1%100!=0)
                 book[i].et+=(24*60);
             }
             else
             {
                  if((i1%400==0||i1%4==0&&i1%100!=0)&&2<em)
                  book[i].et+=(24*60);
                  for(j=1;j<em; j++)
                  book[i].et+=(d[j]*60*24);
             }
          }
      sort(book,book+b,cmp);
      int tim[5005],k=0;
      tim[k++]=book[0].et;
      for(i=1;i<b;i++)//关建要注意的
      {
          for(j=0;j<k;j++)
          if(Fun(tim[j],book[i].st)==0)
            break;
            if(j==k){
                ans+=1;
                tim[k++]=book[i].et;
            }
            else
            tim[j]=book[i].et;
      }
       printf("%d\n",ans);
    }
    return 0;
}

抱歉!评论已关闭.