'commit'
This commit is contained in:
43
TangDou/LanQiaoBei/LanQiao14STEMA202211/3.cpp
Normal file
43
TangDou/LanQiaoBei/LanQiao14STEMA202211/3.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user