您的位置:首页 > 产品设计 > UI/UE

PAT 1017. Queueing at Bank (25)

2014-10-31 22:41 351 查看
//一遍ac


//做的比较仔细,按步骤输出调试了很多细节,最后提交一遍过~!
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
#define BEGIN 8*60*60
#define END 17*60*60
int n, k;
struct customer{
int arrive_time;
int process_time;
int waiting_time;
};
vector<customer> ctr;
bool cmp(const customer& a, const customer& b){
return a.arrive_time < b.arrive_time;
}
int cleartime[105] = { 0 };
int i = 0, j = 0;
int main(){
cin >> n >> k;
for (i = 0; i < n; i++){
customer ctr_tmp;
int hh, mm, ss; char ch;
cin >> hh >> ch >> mm >> ch >> ss;
ctr_tmp.arrive_time = hh * 60 * 60 + mm * 60 + ss;
int m; cin >> m;
ctr_tmp.process_time = 60 * m;
ctr_tmp.waiting_time = 0;
ctr.push_back(ctr_tmp);
}
sort(ctr.begin(), ctr.end(), cmp);
i = 0;
while (i < n&&ctr[i].arrive_time < BEGIN){
ctr[i].waiting_time = BEGIN - ctr[i].arrive_time;
ctr[i].arrive_time = BEGIN;
i++;
}
j = n - 1;
while (j >= 0 && ctr[j].arrive_time >= END){
ctr.pop_back();
j--;
}
int size = j + 1;
//下面按照窗口数目进行第一轮入队
for (j = 0; j < k&&j < size; j++){
cleartime[j] = ctr[j].arrive_time + ctr[j].process_time;
}
for (; j < size; j++){//后面的客户依次入队办理
int index = 0; int min_time = cleartime[0];
for (int v = 0; v < k; v++){
if (cleartime[v] < min_time){
min_time = cleartime[v];
index = v;
}
}
if (min_time <= ctr[j].arrive_time)
cleartime[index] = ctr[j].arrive_time + ctr[j].process_time;
else{
ctr[j].waiting_time += (min_time - ctr[j].arrive_time);
cleartime[index] += ctr[j].process_time;
}
}
float result = 0;
for (int v = 0; v < size; v++){
result += ctr[v].waiting_time;
}
result /= size;
result /= 60;
printf("%.1f", result);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: