Make the Most (Hackerrank Codeagon)
Problem Statement
Codenation is sending N of its employees to a High Profile Business Conference and the goal is to cover maximum number of presentations, to create maximum business opportunities. It has a list of all the presentations with their start and end times. You need to help Codenation decide an optimal allocation.
The start and end times of a presentation are provided to you as a single string and are separated by a space.
Each time is given in the form HH:MM and represents a time between 08:00 in the morning and 08:00 in the evening inclusive.
Input Format
First line contains an integer N (number of employees).
The second line contains integer P (number of presentations).
P lines follow each having conference start time and end time separated by a space.Constraints
1≤N≤10
1≤P≤50
Each of P lines will contain 11 characters in the formHH:MM HH:MM.
Each HH:MM will represent a time between 8 am and 8 pm inclusive.
Each MM will be between 00 and 59, inclusive.
In each element of presentations the second time will be strictly later than the first.Output Format
Print the maximum number of presentations that can be attended.Note: We can assume the time taken for going from one presentation to another is negligible; i.e. if end time of one presentation is same time as start time of another, a single person can cover both presentations from start to end.
Sample Input#00
3
5
08:00 08:00
08:00 08:00
08:00 08:00
08:00 08:00
08:00 08:00
Sample Output#00
3
Explanation#00
All these presentations last all day long. Nobody can cover more than one.
Sample Input#01
2
5
09:00 08:00
08:00 12:00
12:00 08:00
08:00 08:00
08:00 08:00
Sample Output#01
3
Explanation#01
One person can cover the 8-12 presentation and the 12-8 presentation. The other person can cover one of the all-day presentation.Sample Input#02
1
5
08:00 01:00
08:25 12:50
12:00 12:30
12:30 08:00
08:00 08:00
Sample Output#02
2
题目分析:
实际上是个作业安排问题的扩展问题。即给定N个会议,每个会议有开始时间和结束时间,有M个人,问M个人最多总共可以参加多少场会议。
如果M=1,当然就是按照结束时间排序,即可。
这里只需要简单的变形一下,设b[j]为第j个人当前所位于的时间点(初始都为0), 对于第i个会议,如果有多个满足条件的人,选择b[j]最大的那个。
附上代码:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std; typedef pair<int, int> pii;
#define F first
#define S second int main() {
int N, P;
scanf("%d %d", &N, &P);
pii t[];
for (int i = ; i < P; i++) {
int h1, m1, h2, m2, start, end;
scanf("%d:%d %d:%d", &h1, &m1, &h2, &m2);
start = (h1 >= ? (h1 - ) * : (h1 + ) * ) + m1;
end = ((h2 > || h2 == && m2) ? (h2 - ) * : (h2 + ) * ) + m2;
t[i] = pii(end, start);
}
sort(t, t + P);
for (int i = ; i < P; i++) cerr << t[i].S << ' ' << t[i].F << endl;
int ans = ;
int now[] = {};
for (int i = ; i < P; i++) {
int x = -, last = -;
for (int j = ; j < N; j++) {
if (t[i].S >= now[j]) {
if (now[j] > last) {
x = j;
last = now[j];
}
}
}
if (x != -) {
ans++;
now[x] = t[i].F;
}
}
printf("%d\n", ans); return ;
}
Make the Most (Hackerrank Codeagon)的更多相关文章
- 日常小测:颜色 && Hackerrank Unique_colors
题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...
- HackerRank "Square Subsequences" !!!
Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...
- HackerRank "Minimum Penalty Path"
It is about how to choose btw. BFS and DFS. My init thought was to DFS - TLE\MLE. And its editorial ...
- HackerRank "TBS Problem" ~ NPC
It is marked as a NPC problem. However from the #1 code submission (https://www.hackerrank.com/Charl ...
- HackerRank Extra long factorials
传送门 今天在HackerRank上翻到一道高精度题,于是乎就写了个高精度的模板,说是模板其实就只有乘法而已. Extra long factorials Authored by vatsalchan ...
- HackerRank "Lucky Numbers"
Great learning for me:https://www.hackerrank.com/rest/contests/master/challenges/lucky-numbers/hacke ...
- HackerRank "Playing with numbers"
This is 'Difficult' - I worked out it within 45mins, and unlocked HackerRank Algorithm Level 80 yeah ...
- HackerRank "The Indian Job"
A sly knapsack problem in disguise! Thanks to https://github.com/bhajunsingh/programming-challanges/ ...
- HackerRank "Array and simple queries" !
The most interesting, flexible and juicy binary tree problem I have ever seen. I learnt it from here ...
随机推荐
- (转)Android中RelativeLayout各个属性的含义
转:http://blog.csdn.net/softkexin/article/details/5933589 android:layout_above="@id/xxx" - ...
- Wed Nov 01 13:03:16 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended.
报错:Wed Nov 01 13:03:16 CST 2017 WARN: Establishing SSL connection without server's identity verifica ...
- linq to sql any和all的区别
Any说明:用于判断集合中是否有元素满足某一条件:不延迟.(若条件为空,则集合只要不为空就返回True,否则为False).1.简单形式:仅返回没有订单的客户:var q =from c in db. ...
- ansible 安装及基本使用
1.yum 安装 yum -y install epel-releaseyum -y install ansible ansible 配置秘钥 ssh-keygen -t rsa #直接回车不用设置密 ...
- P4860 Roy&October之取石子II
4的倍数不行,之间的数都可以到4的倍数,而6的倍数不能到4的倍数 #include <iostream> #include <cstdio> #include <queu ...
- C++ 判断是否为邮箱格式
总结了一下合法的email地址格式如下: 1. 首字符必须用字母,而且其它的字符只能用26个大小写字母.0~9及_-.@符号 2. 必须包含一个并且只有一个符号“@” 3. @后必须包含至少一个至多三 ...
- springboot thymeleaf ----服务端渲染html
一. 引用命名空间 <html xmlns:th="http://www.thymeleaf.org"> 不这么写 html标签没闭合会报错 二.实际内容在../sta ...
- SQL中的long text
SQL中的long text 问题: 解决方法: SELECT CONVERT(VARCHAR(5000),参考文献) AS 参考文献 FROM tpi20160503 出现原因:
- solusvm 主控端迁移
难点在于solusvm被控端已经开了小鸡的情况. 备份数据库: #!/bin/sh ## Vars CONF=/usr/local/solusvm/includes/solusvm.conf FILE ...
- VS 断点不会命中的情况
总结下遇到的几次断点无法命中的情况: 1.手误设置为release模式 如果是release模式的情况下,断点跳转命中情况是无法预知的,所以请修改成debug 2.与源文件不一致 这个情况是最常见的, ...