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;
}
相关文章推荐
- 浙江大学PAT_甲级_1062. Talent and Virtue (25)
- PAT A 1106. Lowest Price in Supply Chain (25)
- PAT (Advanced Level)1037. Magic Coupon (25)
- Spring.NET学习笔记25——整合Quartz.NET(应用篇) Level 200
- 1062. Talent and Virtue (25)
- Fedora 25 Workstation 安装步骤
- pat 甲级 1098. Insertion or Heap Sort (25)
- Hibernate学习25 -- 延迟加载2 -- 集合Lazy特征
- 1075. PAT Judge (25)
- 每天一个 Linux 命令(25):Linux 文件属性详解
- 乙级 PAT 1060. 爱丁顿数(25)
- 项目管理手记(25) ERP实施顾问会如何看待自己的职业
- 1083. List Grades (25)
- Fedora25和win10双系统安装及使问题汇总
- pat 甲级 1078. Hashing (25)
- Qt学习之路(25): QPainter(续)
- 面试题 25
- Fedora25 将eclipse的快捷方式添加到Applications中
- pat甲级1074. Reversing Linked List (25)、乙级1025. 反转链表 (25)