当前位置:网站首页>华为面试题: 招聘
华为面试题: 招聘
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;
}
边栏推荐
- CPI tutorial - asynchronous interface creation and use
- leetcode 406. Queue reconstruction by height
- 腾讯安全发布《BOT管理白皮书》|解读BOT攻击,探索防护之道
- [datawhale202206] pytorch recommendation system: recall model DSSM & youtubednn
- Chained storage of queues
- Circular linked list--
- Unity xlua co process packaging
- Golang des-cbc
- leetcode 406. Queue Reconstruction by Height(按身高重建队列)
- Talk about biological live broadcast - genovis Zhang Hongyan antibody specific enzyme digestion technology helps to characterize the structure of antibody drugs
猜你喜欢
![[datawhale202206] pytorch recommendation system: multi task learning esmm & MMOE](/img/8f/64fea641730795a2b5252cc2c8cdd2.png)
[datawhale202206] pytorch recommendation system: multi task learning esmm & MMOE

Onenet Internet of things platform - create mqtts products and devices

The Missing Semester

One year anniversary of bitbear live studio, hero rally order! I invite you to take a group photo!

消息队列之监控退款任务批处理过程

谈思生物直播—GENOVIS张洪妍抗体特异性酶切技术助力抗体药物结构表征

91. (cesium chapter) cesium rocket launch simulation

Self organization is the two-way rush of managers and members

【语音信号处理】3语音信号可视化——prosody

IOS interview
随机推荐
[Yu Yue education] financial management reference materials of Ningbo University of Finance and Economics
The operation process of using sugar to make a large data visualization screen
GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021
【20211129】Jupyter Notebook远程服务器配置
[datawhale202206] pytorch recommendation system: precision model deepfm & DIN
Double linked list related operations
JS related interview questions and answers (1)
ANSI/UL 94 VTM薄质材料垂直燃烧测试
MySQL common functions
消息队列之监控退款任务批处理过程
Four years after graduation: work, resign, get married, buy a house
Ansible的playbook
【20211129】Jupyter Notebook遠程服務器配置
Mysql database knowledge collation
C#依赖注入(直白明了)讲解 一看就会系列
栈的应用——括号匹配问题
I wish you all a happy reunion
Implementation of address book management system with C language
What are the PHP FPM configuration parameters
区间乘积的因子数之和——前缀和思想+定一移二