当前位置:网站首页>華為面試題: 招聘
華為面試題: 招聘
2022-07-01 12:26: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;
}
边栏推荐
- Use of easyexcel
- Talk about biological live broadcast - genovis Zhang Hongyan antibody specific enzyme digestion technology helps to characterize the structure of antibody drugs
- Exploration and practice of inress in kubernetes
- Ansible Playbook
- Ipv6-6to4 experiment
- [datawhale202206] pytorch recommendation system: multi task learning esmm & MMOE
- Machine learning - Data Science Library - day two
- 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/
- [JS advanced] promise explanation
- Understanding of NAND flash deblocking
猜你喜欢

Chapter 14 signals (IV) - examples of multi process tasks

顺序表有关操作

The Missing Semester

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

91.(cesium篇)cesium火箭發射模擬
![[106] 360 check font - check whether the copyright of local Fonts is commercially available](/img/a7/615e8000647b56f03a6a1d3dd81b6d.jpg)
[106] 360 check font - check whether the copyright of local Fonts is commercially available
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2](/img/2b/f42ac6745eb126254af62ad5217f70.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2

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

栈-------

Queue operation---
随机推荐
[datawhale202206] pytorch recommendation system: precision model deepfm & DIN
JPA and criteria API - select only specific columns - JPA & criteria API - select only specific columns
腾讯黎巍:深耕“监管科技”,护航数字经济行稳致远
Le semester manquant
6.30模拟赛总结
Typora realizes automatic uploading of picture pasting
比特熊直播间一周年,英雄集结令!邀你来合影!
循环链表--
Onenet Internet of things platform - create mqtts products and devices
Switch basic experiment
区间乘积的因子数之和——前缀和思想+定一移二
【MAUI】为 Label、Image 等控件添加点击事件
消息队列之监控退款任务批处理过程
Message queue monitoring refund task batch process
Dlhsoft Kanban, Kanban component of WPF
Virtualenv+pipenv virtual environment management
Uniapp uses uni upgrade Center
【datawhale202206】pyTorch推荐系统:精排模型 DeepFM&DIN
ASP. Net core 6 from entry to enterprise level practical development application technology summary
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐