You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
/*
测试用例I
7
3 5 2 4 7 1 6
整体时长
10 12 6
答案6
--------
测试用例II
2
1 100
期望答案0
*/
using namespace std;
int a[4]; //每个窗口的工作累加时长
int n, b[60]; // n:客户个数b[i]:i这个客户办理业务需要的时长
int p; //现在该轮到哪个用户办理了
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> b[i];
// 1、计时器,不喜欢while(true),用for循环替代
for (int t = 0;; t++) {
// 2、哪个窗口办理完毕
for (int i = 1; i <= 3; i++) {
if (a[i] == t) { //如果累计时长等于当前时长,说明现在正好办理完毕
a[i] += b[++p]; //将i窗口安排上++p这个客户增加b[++p]的时长
if (p > n) { //到当前窗口时,没有客户了,说明当前窗口是最早结束任务的,直接输出当前的时间
cout << t << endl;
return 0;
}
}
}
}
return 0;
}