题目链接

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. js 常见功能总会

    一.随着页面滚动,元素到达可视区域,显示特殊样式 <!DOCTYPE html> <html lang="en"> <head> <met ...

  2. System.Web.Mvc.HttpOptionsAttribute.cs

    ylbtech-System.Web.Mvc.HttpOptionsAttribute.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutra ...

  3. springboot整合mybatis进行跨库查询

    业务场景: 当一个公司大了之后就会将各种业务进行分开,最简单的就是例如:公司的机构表,那么就会将他们分成开来,那么就会在一个实例中, 如果要获取相关信息就会去关联这张表进行关联查询 从而导致了跨库关联 ...

  4. 自动生成DTO(Sugar框架)

    step1:启动api项目 step2:使用postman工具,填上接口地址http://localhost:7788/api/automapper/AutoMapperSuper step3:表格数 ...

  5. python语句结构(控制语句与pass语句)

    python语句结构(控制语句和pass语句) break-跳出循环:语句可以跳出for和while语句的循环体.如果你从for和while循环中终止,任何对应循环的else语块均终止 continu ...

  6. springcloud(十五):服务网关zuul

    前面的文章我们介绍了,Eureka用于服务的注册于发现,Feign支持服务的调用以及均衡负载,Hystrix处理服务的熔断防止故障扩散,Spring Cloud Config服务集群配置中心,似乎一个 ...

  7. Geoserver的跨域问题

    使用tomcat访问Geoserver服务的时候,只调服务没问题,但是查询要素属性的时候出现如下“XMLHttpRequest”.“not allowed by Access-Control-Allo ...

  8. 数据库DQL、DML、DDL及DCL详解

    目录 1. 数据查询语言(DQL,Data Query Language) 2. 数据操纵语言(DML,Data Manipulation Language) 3. 数据定义语言(DDL,Data D ...

  9. android中实现监听的四种方法

    (1)自身类作为事件监听器 package cn.edu.gdmec.s07150745.work5; import android.support.v7.app.AppCompatActivity; ...

  10. MyBatis与Hibernate

    Mybatis和hibernate不同,它不完全是一个ORM框架,因为MyBatis需要程序员自己编写Sql语句.mybatis可以通过XML或注解方式灵活配置要运行的sql语句,并将java对象和s ...