German Collegiate Programming Contest 2013-B:Booking(贪心)
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(贪心)的更多相关文章
- German Collegiate Programming Contest 2013:E
数值计算: 这种积分的计算方法很好,学习一下! 代码: #include <iostream> #include <cmath> using namespace std; ; ...
- German Collegiate Programming Contest 2013:B
一个离散化的简单题: 我用的是STL来做的离散化: 好久没写离散化了,纪念一下! 代码: #include<cstdio> #include<cstring> #include ...
- 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 ...
- 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 ...
- 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. ...
- 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: ...
- 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, ...
- 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 ...
- 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 ...
随机推荐
- angular4,angular6 父组件异步获取数据传值子组件 undefined 问题
通过输入和输出属性 实现数据在父子组件的交互在子组件内部使用@input接受父组件传入数据,使用@output传出数据到父组件详细标准讲解参考官方文档https://angular.cn/guide/ ...
- JavaScipt 中的事件循环(event loop),以及微任务 和宏任务的概念
说事件循环(event loop)之前先要搞清楚几个问题. 1. js为什么是单线程的? 试想一下,如果js不是单线程的,同时有两个方法作用dom,一个删除,一个修改,那么这时候浏览器该听谁的? ...
- 基于Redis+MySQL+MongoDB存储架构应用
摘 要: Redis+MySQL+MongoDB技术架构实现了本项目中大数据存储和实时云计算的需求.使用MongoDB切片的水平动态添加,可在不中断平台业务系统的同时保障扩容后的查询速度和云计算效能 ...
- nginx:负载均衡实战(二) keepalived入门
1.keepalived介绍 顾名思义,keepalived就是保持网络在线的,用来保证集群高可用HA的服务软件.主要防止出现单点故障(坏了一个点导致整个系统架构不可用) 2.详解keepalived ...
- day056 多表增加和查询
今日总结: 多表的增删改查操作 多表操作 增 book id title book_detail publish author onetoone manytoone manytomany book_o ...
- 前端基础之jQuery操作标签
一.样式操作 样式类 addClass(); // 添加指定的CSS类名. removeClass(); // 移除指定的CSS类名. hasClass(); // 判断样式存不存在 toggleCl ...
- powerdesigner 使用
1. 首先要确保机器安装了MySql的ODBC驱动,去http://dev.mysql.com/downloads/connector/odbc/5.1.html 下载 Connector/ODBC ...
- Centos7部署kubectl命令行工具(五)
1.准备二进制包 [root@linux-node1 ~]# cd /usr/local/src/kubernetes/client/bin [root@linux-node1 bin]# cp ku ...
- tomcat启动失败,提示信息:Unable to ping server at localhost:1099
jdk1.7+maven9.0.0开启服务器时,提示Unable to ping server at localhost:1099 然后换成tomcat8.5.1就成功开启服务器
- 国行 lg g3 D858 刷 lg g3 D858hk 教程(备忘)
纯手打,转载请注明出处~ 刷机有风险,出现问题概不负责! 本着自娱自乐的宗旨 ,分享一下,出了问题不负责! 准备的材料: 1,手机一枚(废话)国行lg g3 d858 2,root 工具 用来root ...