招聘
标题:招聘 | 时间限制:1秒 | 内存限制:262144K | 语言限制:不限
某公司组织一场公开招聘活动,假设由于人数和场地的限制,每人每次面试的时长不等,并已经安排给定,用(S1,E1)、(S2,E2)、(Sj,Ej)...(Si < Ei,均为非负整数)表示每场面试的开始和结束时间。面试采用一对一的方式,即一名面试官同时只能面试一名应试者,一名面试官完成一次面试后可以立即进行下一场面试,且每个面试官的面试人次不超过m。
为了支撑招聘活动高效顺利进行,请你计算至少需要多少名面试官
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool compare(const pair<int, int>& p1, const pair<int, int>& p2)
{
if (p1.first == p2.first) {
return p1.second < p2.second;
}
else {
return p1.first < p2.first;
}
}
int getMinCount(vector<pair<int, int>> v, int n, int m, int* ans)
{
if (v.size() == 0) {
return *ans;
}
if (v.size() == 1) {
return (*ans) +1;
}
int k = 0;
vector<pair<int, int>> vt;
int lastIndex = -1;
for (int i = 0; i < v.size(); i++) {
if (i > 0 &&lastIndex!=-1&& v[i].first < v[lastIndex].second) {
vt.push_back(v[i]);
continue;
}
lastIndex = i;
k++;
if (k == m) {
(*ans)++;
k = 0;
}
}
if (k != 0) {
(*ans)++;
}
return getMinCount(vt, n, m, ans);
}
int main()
{
int n, m;
vector<pair<int, int>> v;
cin >> m >> n;
for (int i = 0; i < n; i++) {
pair<int, int> p;
cin >> p.first >> p.second;
v.push_back(p);
}
sort(v.begin(), v.end(), compare);
int ans = 0;
cout << getMinCount(v, n, m, &ans);
}
def is_vaild(hr, plan_): def compare(ls1, ls2): a, b = ls1[0], ls1[1] c, d = ls2[0], ls2[1] return a < c < b or a < d < b or (a >= c and b <= d) for hr_ in hr: if compare(hr_, plan_) or compare(plan_, hr_): return False return True def get_ans(plan_): for hr in hrs: if len(hr) >= m: continue if is_vaild(hr, plan_): hr.append(plan_) return True while True: try: m, n = int(input()), int(input()) plans = sorted([[int(i) for i in input().split()] for _ in range(n)], key=lambda x: x[0]) hrs = [] for plan in plans: if not get_ans(plan): hrs.append([plan]) print(len(hrs)) except: break //manfen
m, n = int(input()), int(input()) def read(): return [int(i) for i in input().split()] all_time = [read() for i in range(n)] all_time = sorted(all_time, key=lambda x: x[0]) users = [] def can_save(a, b): if (a[0] < b[0] < a[1]) or (a[0] < b[1] < a[1]): return True elif a[0] >= b[0] and a[1] <= b[1]: return True return False def save(time): global users for user in users: if len(user) >= m: continue is_save = True for t in user: if can_save(t, time) or can_save(time, t): is_save = False break if is_save: user.append(time) return True return False def run(): for time in all_time: if not save(time): users.append([time]) print(len(users)) run()

查看11道真题和解析