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

1017. Queueing at Bank (25)

2016-09-24 21:48 260 查看

1017. Queueing at Bank (25)

时间限制
400 ms

内存限制
65536 kB

代码长度限制
16000 B

判题程序
Standard

作者
CHEN, Yue

Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be served and there is
a window available. It is assumed that no window can be occupied by a single customer for more than 1 hour.

Now given the arriving time T and the processing time P of each customer, you are supposed to tell the average waiting time of all the customers.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 numbers: N (<=10000) - the total number of customers, and K (<=100) - the number of windows. Then N lines follow, each contains 2 times: HH:MM:SS - the arriving time, and P
- the processing time in minutes of a customer. Here HH is in the range [00, 23], MM and SS are both in [00, 59]. It is assumed that no two customers arrives at the same time.

Notice that the bank opens from 08:00 to 17:00. Anyone arrives early will have to wait in line till 08:00, and anyone comes too late (at or after 17:00:01) will not be served nor counted into the average.

Output Specification:

For each test case, print in one line the average waiting time of all the customers, in minutes and accurate up to 1 decimal place.

Sample Input:
7 3
07:55:00 16
17:00:01 2
07:59:59 15
08:01:00 60
08:00:00 30
08:00:02 2
08:03:00 10

Sample Output:
8.2

主要是对应关系...sort的时候另一个值可能会不跟着变化,考虑过用结构体,但是空间感觉不够,改用pair感觉又不好,考虑了很久决定用数组,暴力解决

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<set>
#include<string>
using namespace std;

int p[100002];

int main()
{
int n, k;
cin >> n >> k;
int time
;

for (int i = 0; i < n; i++)
{
int hh, mm, ss;
scanf("%d:%d:%d", &hh, &mm, &ss);
time[i] = hh * 3600 + mm * 60 + ss;
int eg;
cin >> eg;
if (eg > 60) p[time[i]] = 60;
else p[time[i]] = eg;
}
sort(time, time + n);

set<int> test;
double wait=0;
int num=n;
int a=p[8*3600];
for (int i = 0; i < n; i++)
{

if (time[i] < 8 * 3600) {
wait += 8 * 3600 - time[i];
//cout<<"---"<<wait<<endl;
p[8*3600]=p[time[i]];
time[i] = 8 * 3600;
}
else if (time[i] > 17 * 3600) {
num--;continue;
}
else if(time[i]==8*3600) p[8*3600]=a;
set<int>::iterator iter = test.begin();
if (test.size() < k)
{
test.insert(time[i]+p[time[i]]*60);
//cout<<"p--"<<p[time[i]]<<endl;
}
else if (test.size() >= k)
{
if (*iter <= time[i])
{
test.erase(iter);
test.insert(time[i]+p[time[i]]*60);
//cout<<p[time[i]]<<endl;
}
else if (*iter > time[i]) {
wait += *iter - time[i];
test.erase(iter);
test.insert(*iter+p[time[i]]*60);
//cout<<i<<endl;
}
}
//cout<<wait<<endl;
}
//cout<<wait<<endl;
//cout<<num<<endl;
wait=wait/60;
printf("%.1f", wait / num);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: