PAT1017:Queueing at Bank
1017. Queueing at Bank (25)
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 思路
贪心策略,将办理业务的人按到达时间递增排序,先来的优先服务(将时间统一转换为秒方便计算)。
注意:
1.业务办理时间不应超过1小时。
2.17点之后来的人不提供服务。
3.一个窗口的空闲时刻有两种情况:
1)空闲直到下一个人customer[i]到达银行办理业务,那么这个窗口的下一个空闲时刻为customer[i]的到达时间加上他办理业务需要的时间。
2)如果在一个窗口空闲前,custmoer[i]就先来了,那么他需要等(窗口空闲时间-他到达的时间)这么一段时间。该窗口的下一个空闲时刻就是它当前空闲时刻加上customer[i]的业务办理时间。 代码
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
class person
{
public:
int cometime;
int taketime;
person(int ct,int tt)
{
cometime = ct;
taketime = tt;
}
}; /*贪心策略 先来的先服务,有空窗口就服务*/ bool cmp(const person& a,const person& b)
{
return a.cometime < b.cometime;
} int main()
{
int N,K;
vector<person> customer;
while(cin >> N >> K)
{
vector<int> windows(K,28800);
for(int i = 0;i < N;i++)
{
int hh,mm,ss,lasttime;
scanf("%d:%d:%d %d",&hh,&mm,&ss,&lasttime);
if(lasttime > 60)
lasttime = 60;
lasttime *= 60;
int arrivetime = hh * 3600 + mm * 60 + ss;
if(arrivetime > 61200)
continue;
customer.push_back(person(arrivetime,lasttime));
}
sort(customer.begin(),customer.end(),cmp);
double waitTime = 0;
for(int i = 0;i < customer.size();i++)
{
int minwindow = windows[0],tmpindex = 0;
for(int j = 0;j < K;j++)
{
if(windows[j] < minwindow)
{
minwindow = windows[j];
tmpindex = j;
}
}
if(customer[i].cometime >= minwindow)
{
windows[tmpindex] = customer[i].cometime + customer[i].taketime;
}
else
{
waitTime += minwindow - customer[i].cometime;
windows[tmpindex] += customer[i].taketime;
}
}
if(customer.empty())
cout << "0.0" << endl;
else
cout << fixed << setprecision(1) << waitTime/60.0/customer.size() << endl;
}
}
PAT1017:Queueing at Bank的更多相关文章
- pat1017. Queueing at Bank (25)
1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...
- PAT甲级1017. Queueing at Bank
PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...
- PAT 1017 Queueing at Bank[一般]
1017 Queueing at Bank (25)(25 分)提问 Suppose a bank has K windows open for service. There is a yellow ...
- PAT 1017 Queueing at Bank (模拟)
1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...
- PAT 甲级 1017 Queueing at Bank (25 分)(模拟题,有点思维小技巧,第二次做才理清思路)
1017 Queueing at Bank (25 分) Suppose a bank has K windows open for service. There is a yellow line ...
- pat——1017. Queueing at Bank (java中Map用法)
由PAT1017例题展开: Suppose a bank has K windows open for service. There is a yellow line in front of the ...
- 1017. Queueing at Bank (25)
Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...
- PAT 1017. Queueing at Bank
Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...
- 1017. Queueing at Bank (25) - priority_queuet
题目如下: Suppose a bank has K windows open for service. There is a yellow line in front of the windows ...
随机推荐
- 【UML 建模】UML建模语言入门 -- 静态图详解 类图 对象图 包图 静态图建模实战
发现个好东西思维导图, 最近开始用MindManager整理博客 . 作者 :万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/deta ...
- TCP 的那些事儿(上)(转)
本文转载自陈皓博文TCP 的那些事儿(上). TCP是一个巨复杂的协议,因为他要解决很多问题,而这些问题又带出了很多子问题和阴暗面.所以学习TCP本身是个比较痛苦的过程,但对于学习的过程却能让人有很多 ...
- Chrome浏览器开发调试系列(一)
// 计划写一个 Chrome 浏览器以及 调试器的系列文章,我慢慢写. 边写边改,发觉博客真是个打草稿的好地方. // 本文针对的是当前最新的浏览器Chrome34,如果你的版本不够新,希望你能够更 ...
- 校招:Vobile阜博通2015校园招聘
关于Vobile阜博通校招(10-11月份),耗时将近一个月,现整理分享给大家. 1 浙大笔试无选择填空,问答题为主,偏语言的个人理解,不在意具体语言方向(C/C++/Java).(1)描述C.C++ ...
- apktool动态破解apk
那么今天我们就用另外一种方式来破解apk:动态方式,关于动态方式其实很广义的,因为动态方式相对于静态方式来说,难度大一点,但是他比静态方式高效点,能够针对更过的破解范围.当然动态方式很多,所以这里就分 ...
- Media Player Classic - HC 源代码分析 4:核心类 (CMainFrame)(3)
===================================================== Media Player Classic - HC 源代码分析系列文章列表: Media P ...
- hbase thrift 访问队列
public class CallQueue implements BlockingQueue<Runnable> { private static Log LOG = LogFact ...
- Slop One 算法
Slope One 算法是由 Daniel Lemire 教授在 2005 年提出的一个 Item-Based 推荐算法. Slope One 算法试图同时满足这样的的 5 个目标: 易于实现和维护: ...
- SharePoint2010 -- ECMAScript客户端模型简单示例
ECMAScript客户端模型,是SharePoint2010推出的三种客户端模型".NET托管"."ECMAScript"."Sliverlight ...
- 容器(list集合)
--为什么使用集合而不使用数组?why ·集合和数组相似点:都可以存储多个对象,对外作为一个整体存在: ··数组的缺点:1.长度必须在初始化时指定,且固定不变: 2.数组采用连续存储空间,删除和添加元 ...