当前位置:网站首页>华为面试题: 招聘
华为面试题: 招聘
2022-07-01 12:25:00 【四库全书的酷】
题目
某公司组织一场公开招聘活动,假设由于人数和场地的限制,每人每次面试的时长不等,并已经安排给定,用 (S1, E1)、 (S2, E2)、 (Sj,Ej)…(Si < Ei ,均为非负整数 )表示每场面试的开始和结束时间。面试采用一对一的方式,即一名面试官同时只能面试一名应试者,一名面试官完成一次面试后可以立即进行下一场面试,且每个面试官的面试人次不超过 m 。
为了支撑招聘活动高效顺利进行,请你计算至少需要多少名面试官。
输入描述
输入的第一行为面试官的最多面试人次 m ,第二行为当天总的面试场次 n ,接下来的 n 行为
每场面试的起始时间和结束时间,起始时间和结束时间用空格分隔。 其中, 1 <= n, m <= 500
输出描述
输出一个整数,表示至少需要的面试官数量。
示例1
输入
2
5
1 2
2 3
3 4
4 5
5 6
输出
3
说明 :
总共有5 场面试,且面试时间都不重叠,但每个面试官最多只能面试 2 人次,所以需要 3 名面试官。
示例2
输入
3
3
1 2
2 3
3 4
输出
1
说明:
总共有3 场面试,面试时间都不重叠,每个面试官最多能面试 3 人次,所以只需要 1 名面试官。
示例3
输入
3
3
8 35
5 10
1 3
输出
2
说明:
总共有3 场面试【5,10】和 【8,35】 有重叠,所以至少需要 2 名面试官。
分析
首先进行一下排序,然后用一个大顶堆,维护当前每次面试的结束时间,
然后当一个新的时间安排出现的时候,只需要判断一下是否需要新的一个面试官,还是继续使用之前的会议室。
代码
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int m,n;
cin >> m >> n;
vector<pair<int,int>> cap;
for(int i = 0; i < n; ++i){
int tmp1,tmp2;
cin >> tmp1 >> tmp2;
cap.push_back({
tmp1,tmp2});
}
sort(cap.begin(),cap.end(),[](pair<int,int>&a, pair<int,int>&b){
return a.first < b.first;
});
vector<priority_queue<int>> cap2(1);
for(int i = 0; i < cap.size(); ++i){
auto x = cap[i];
priority_queue<int> tmp;
int flag = 1;
for(int i = 0; i < cap2.size(); ++i){
if(cap2[i].empty() || cap2[i].top() <= x.first){
cap2[i].push(x.second);
flag = 0;
break;
}
}
if(flag){
tmp.push(x.second);
cap2.push_back(tmp);
}
}
int ans = 0;
for(int i = 0;i < cap2.size(); ++i){
int tmp = cap2[i].size();
ans += tmp % m ? (tmp / m + 1) : ( tmp / m );
}
cout << ans << endl;
return 0;
}
边栏推荐
猜你喜欢
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 5](/img/f5/9c68b3dc30362d3776c262fdc13fd0.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 5

Joint Time-Frequency and Time Domain Learning for Speech Enhancement

【20220605】文献翻译——虚拟现实中的可视化:一个系统的回顾

Technology sharing | MySQL: how about copying half a transaction from the database?

Sort out relevant contents of ansible

GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021

【datawhale202206】pyTorch推荐系统:精排模型 DeepFM&DIN
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 3](/img/ea/c5e8d12007873385fa0d197fa62fd2.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 3
![Wechat applet reports an error: [rendering layer network layer error] pages/main/main Local resource pictures in wxss cannot be obtained through wxss. You can use network pictures, Base64, or < image/](/img/6a/fe448ca635690bc5260436546b588e.jpg)
Wechat applet reports an error: [rendering layer network layer error] pages/main/main Local resource pictures in wxss cannot be obtained through wxss. You can use network pictures, Base64, or < image/
![[20211129] configuration du serveur distant du carnet de notes jupyter](/img/7c/79c9fcb91bde75e954dc3ecf9f5afd.png)
[20211129] configuration du serveur distant du carnet de notes jupyter
随机推荐
[datawhale202206] pytorch recommendation system: multi task learning esmm & MMOE
腾讯黎巍:深耕“监管科技”,护航数字经济行稳致远
Joint Time-Frequency and Time Domain Learning for Speech Enhancement
Le semester manquant
二叉树的链式存储
[speech signal processing] 3 speech signal visualization -- prosody
91.(cesium篇)cesium火箭发射模拟
Implementation of address book management system with C language
Fatal error: execution: there is no such file or directory
Circular linked list--
使用BurpSuite对app抓包教程
AI抠图工具
GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021
技术分享 | MySQL:从库复制半个事务会怎么样?
腾讯安全发布《BOT管理白皮书》|解读BOT攻击,探索防护之道
MySQL common functions
GPS 数据中的精度因子(DOP)与协方差之间的关系 (参考链接)
IOS interview
Ansible相关内容梳理
BIM and safety in road maintenance-buildSmart Spain