题目链接

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 form HH: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)的更多相关文章

  1. 日常小测:颜色 && Hackerrank Unique_colors

    题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...

  2. HackerRank "Square Subsequences" !!!

    Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...

  3. 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 ...

  4. HackerRank "TBS Problem" ~ NPC

    It is marked as a NPC problem. However from the #1 code submission (https://www.hackerrank.com/Charl ...

  5. HackerRank Extra long factorials

    传送门 今天在HackerRank上翻到一道高精度题,于是乎就写了个高精度的模板,说是模板其实就只有乘法而已. Extra long factorials Authored by vatsalchan ...

  6. HackerRank "Lucky Numbers"

    Great learning for me:https://www.hackerrank.com/rest/contests/master/challenges/lucky-numbers/hacke ...

  7. HackerRank "Playing with numbers"

    This is 'Difficult' - I worked out it within 45mins, and unlocked HackerRank Algorithm Level 80 yeah ...

  8. HackerRank "The Indian Job"

    A sly knapsack problem in disguise! Thanks to https://github.com/bhajunsingh/programming-challanges/ ...

  9. HackerRank "Array and simple queries" !

    The most interesting, flexible and juicy binary tree problem I have ever seen. I learnt it from here ...

随机推荐

  1. vuecli脚手架+vue+vuex实现vue驱动的demo。

    哎呀呀呀,现在大家都要会Vue ||  React,否则感觉跟这个前端的世界脱节了一样. start: vue-cli这个构建工具大大降低了webpack的使用难度,支持热更新,有webpack-de ...

  2. [Codeplus 4月赛]最短路

    题意:理论上是给定一张完全图,有边权,在给一些单向边求最短路. 思路: 我充分体会到了我图论的菜. 理论上建图肯定是不能\(n^2\)的,考虑如何优化呢? 将边权异或值二进制替换,最后一遍最短路就行, ...

  3. hexo 错误汇总

    文章目录 发布文章遇到: 发布文章的时候出现错误: 代码推送到github,hexo g -d 半天推送不上去 记录一次hexo+coding hexo s本都没问题,hexo g -d 样式并未改变 ...

  4. ASP.NET MVC Controller激活系统详解1

    一.引言 好久没有写博客了,前一段时间学习了Controller激活的一篇很好的博文(链接),在此做个学习总结. 二.Controller 2.1 IController Controller类型直接 ...

  5. 浅析ES的_source、_all、store、index

    Elasticsearch中有大量关键概念容易混淆,对于初学者来说是噩梦: _source字段里存储了什么? index属性的作用是什么? 何时应该开启_all字段? store属性和_source字 ...

  6. <Python基础>装饰器的基本原理

    1.装饰器 所谓装饰器一般是对已经使用(上线)的函数增加功能. 但是因为一般的大公司的严格按照开放封闭原则(对扩展是开放的,对修改是封闭的),不会让你修改原本的函数. 装饰器就是在不改变原本的函数且不 ...

  7. 【主席树】 [CQOI2015]任务查询系统

    模板题... 差分,然后用主席树维护时间点上的优先值和就好了 就是细节烦... #include<bits/stdc++.h> #define int long long #define ...

  8. Leetcode187. Repeated DNA Sequences重复的DNA序列

    所有 DNA 由一系列缩写为 A,C,G 和 T 的核苷酸组成,例如:"ACGAATTCCG".在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮助. 编写一个函数 ...

  9. vue-cli3使用yarn run build打包找不到路径

    vue-cli3使用yarn run build打包项目部署到服务器上面,运行空白 解决办法非常方便,直接创建vue.config.js 在vue.config.js中添加即可 再打包项目即成功

  10. DOM节点克隆

    var newDiv = red.cloneNode();document.body.appendChild(newDiv);注意:1.默认只克隆元素本身:设置参数为true,进行深度克隆,可以克隆元 ...