首页 技术 正文
技术 2022年11月10日
0 收藏 651 点赞 2,681 浏览 2403 个字

题目链接

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 ;
}

    					
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,111
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,584
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,431
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,203
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,838
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,922