Booking

Pierre is in great trouble today! He is responsible for managing the bookings for the ACM (Acco- modation with Moderate Costs) hotel and has just realized that the booking software has a severe   bug. It has created overlapping and wrong room assignments. Pierre is now worried that the hotel might be overbooked. Since the software manufacturer is neither very responsive nor competent, he must check this himself, so that he can timely take countermeasures if necessary.

Fortunately, Pierre was able to export all original bookings (including reservation codes plus correct and valid dates of arrival and departure). The only information that got lost is the time of the booking placements, so that Pierre cannot retrieve any booking priorities (e.g., first-come-first-serve). Using  the available information, could you please help Pierre out and tell him a room assignment with the minimum number of rooms that satisfies all bookings? Please be aware that a room must always be cleaned before reuse. Since Pierre does not want to take any risks, he tells you to only consider the maximum cleaning time.

Input

The input consists of several lines. The first line contains 1 ≤ T ≤ 100, the number of test cases. Each test case starts with a line containing two integers 1 ≤ B ≤ 5 000, the number of bookings, and 0 ≤ C ≤ 360, the cleaning time (in minutes) for one room.

Then follow B lines, each containing the reservation code (a random alphanumeric string of up 20 characters) and the dates of arrival and departure of one booking. Dates are given as strings in the format "YYYY-MM-DD HH:MM" (see example test case), where reservations are only for the years 2013 until 2016.

Output

For each test case, print the minimum number of needed rooms on a single line without any additional blanks. Be aware of leap years but ignore daylight saving time.

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

题意

有n个客人预订房间,但是客人预定的房间给弄乱了,Pierre打扫房间需要m分钟,给出客人预订房间的开始时间和结束时间,求最少要为客人准备多少间房间

思路

活动安排问题模板题,主要是讲给出来的年月日那个时间划分成一个统一的时间标准(以某一个时间作为时间的开始点,时间统一为和该时间点相差多少分钟),然后套模板就能过了(这么简单的题我竟然没有写,当时想到用这个贪心了,但是感觉过不了,就没写QAQ)

活动安排问题讲解传送门:https://blog.csdn.net/wang_123_zy/article/details/79323417

AC代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ull unsigned long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
const double E=exp(1);
const int maxn=1e5+10;
const int mod=1e9+7;
using namespace std;
int times[12]={0,44640,84960,129600,172800,217440,260640,305280,349920,393120,437760,480960};
int a[maxn],b[maxn];
int main(int argc, char const *argv[])
{
int t;
char ch[100];
int id,year,month,day,hour,minute;
scanf("%d",&t);
int n,m;
while(t--)
{
int ans=1;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%s %d-%d-%d %d:%d",ch,&year,&month,&day,&hour,&minute);
if(year==2016&&month>2)
a[i]=(year-2013)*525600+times[month-1]+(day-1)*1440+hour*60+minute+1440;
else
a[i]=(year-2013)*525600+times[month-1]+(day-1)*1440+hour*60+minute;
scanf("%d-%d-%d %d:%d",&year,&month,&day,&hour,&minute);
if(year==2016&&month>2)
b[i]=(year-2013)*525600+times[month-1]+(day-1)*1440+hour*60+minute+1440;
else
b[i]=(year-2013)*525600+times[month-1]+(day-1)*1440+hour*60+minute;
}
int i,k;
sort(a,a+n);
sort(b,b+n);
int sum=0;
for(i=0,k=0;i<n;i++)
{
if(a[i]-b[k]<m)
sum++;
else
k++;
}
printf("%d\n",sum);
}
return 0;
}

German Collegiate Programming Contest 2013-B:Booking(贪心)的更多相关文章

  1. German Collegiate Programming Contest 2013:E

    数值计算: 这种积分的计算方法很好,学习一下! 代码: #include <iostream> #include <cmath> using namespace std; ; ...

  2. German Collegiate Programming Contest 2013:B

    一个离散化的简单题: 我用的是STL来做的离散化: 好久没写离散化了,纪念一下! 代码: #include<cstdio> #include<cstring> #include ...

  3. The Ninth Hunan Collegiate Programming Contest (2013) Problem A

    Problem A Almost Palindrome Given a line of text, find the longest almost-palindrome substring. A st ...

  4. The Ninth Hunan Collegiate Programming Contest (2013) Problem F

    Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...

  5. The Ninth Hunan Collegiate Programming Contest (2013) Problem H

    Problem H High bridge, low bridge Q: There are one high bridge and one low bridge across the river. ...

  6. The Ninth Hunan Collegiate Programming Contest (2013) Problem I

    Problem I Interesting Calculator There is an interesting calculator. It has 3 rows of button. Row 1: ...

  7. The Ninth Hunan Collegiate Programming Contest (2013) Problem J

    Problem J Joking with Fermat's Last Theorem Fermat's Last Theorem: no three positive integers a, b, ...

  8. The Ninth Hunan Collegiate Programming Contest (2013) Problem G

    Problem G Good Teacher I want to be a good teacher, so at least I need to remember all the student n ...

  9. The Ninth Hunan Collegiate Programming Contest (2013) Problem L

    Problem L Last Blood In many programming contests, special prizes are given to teams who solved a pa ...

随机推荐

  1. char和varchar、浮点数和定点数

    cmd连接mysql数据库:找到mysql目录,进入到bin目录,然后在命令行中输入 mysql -hlocalhost -uroot -ppass ,连接mysql数据库成功. 1.char和var ...

  2. thinkphp5多语言

    一.配置 1.'lang_switch_on' => true, 2.'lang_list' => ['zh-cn','en-us',] 二.语言定义() 1.新建文件/en-us.php ...

  3. Win10系列:VC++绘制几何图形4

    三角形绘制完成以后,接下来介绍如何给项目添加主入口函数.打开D2DBasicAnimation.h头文件,添加如下的代码定义一个DirectXAppSource类. //定义类DirectXAppSo ...

  4. 网口扫盲二:Mac与Phy组成原理的简单分析

    1. general 下图是网口结构简图.网口由CPU.MAC和PHY三部分组成.DMA控制器通常属于CPU的一部分,用虚线放在这里是为了表示DMA控制器可能会参与到网口数据传输中. MAC(Medi ...

  5. day04_python_1124

    01 上周内容回顾 int bool str int < --- > str: i1 = 100    str(i1) s1 = '10'    int(s1)字符串必须是数字组成. in ...

  6. java将字符串根据空格进行分割,使用split方法

    public class D { public static void main(String[] args) { String b = "Hello Java World"; S ...

  7. Java中数据类型相互转化

    1 将String 转换成int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([String], ...

  8. 数据泵导入 ORA-31626

    Oracle,10G,数据泵导入时,报错如下: 解决方案:对当前用户做如下授权 . 具体操作:grant connect,resource to user;

  9. day15-python常用内置模块的使用

    在日常的开发工作中,我们要写很多的python代码,如果都写在一个文件中,会导致代码特别难维护,为了拓展代码的可维护性,我们把函写在不同的文件里,这样每个文件包含的文件就比较少,逻辑更加清楚.在pyt ...

  10. day10-高阶函数

    高阶函数 高阶函数:就是把函数当成参数传递的一种函数,例如: def add(x,y,f): return f(x)+f(y) print(add(-8,11,abs)) 结果: 19 解释: 调用a ...