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

思路

贪心策略,将办理业务的人按到达时间递增排序,先来的优先服务(将时间统一转换为秒方便计算)。
注意:
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的更多相关文章

  1. pat1017. Queueing at Bank (25)

    1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...

  2. PAT甲级1017. Queueing at Bank

    PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...

  3. PAT 1017 Queueing at Bank[一般]

    1017 Queueing at Bank (25)(25 分)提问 Suppose a bank has K windows open for service. There is a yellow ...

  4. PAT 1017 Queueing at Bank (模拟)

    1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 关于Android的https通讯安全

    原文链接:http://pingguohe.net/2016/02/26/Android-App-secure-ssl.html 起因 前段时间,同事拿着一个代码安全扫描出来的 bug 过来咨询,我一 ...

  2. Universal-Image-Loader,android-Volley,Picasso、Fresco和Glide图片缓存库的联系与区别

    Universal-Image-Loader,android-Volley,Picasso.Fresco和Glide五大Android开源组件加载网络图片比较 在Android中的加载网络图片是一件十 ...

  3. 虚拟机安装Ubuntu14.04打开FireFox提示Server not found

    虚拟机安装Ubuntu14.04打开FireFox提示Server not found 我采用VMware安装ubuntu14.04的,VMware的网络是配置采用NAT模式(用于共享主机的IP地址) ...

  4. PS图层混合算法之四(亮光, 点光, 线性光, 实色混合)

    亮光模式: 根据绘图色通过增加或降低"对比度",加深或减淡颜色.如果绘图色比50%的灰亮,图像通过降低对比度被照亮,如果绘图色比50%的灰暗,图像通过增加对比度变暗. 线性光模式: ...

  5. SharePoint 2013 页面访问,Url中间多一段&quot;_layouts/15/start.aspx#&quot;

    问题描述: 我想访问如下页面 http://Host/_layouts/15/ManageFeatures.aspx 点击以后页面地址没有错,但是中间多了一段"_layouts/15/sta ...

  6. 手把手教你从头开始搭建友善之臂ARM-tiny4412开发环境(史上最详细!!)

    创建一个ARM目录 mkdir   /disk/A9  -p 接下来你需要准备以下的东西 1.arm-linux-gcc-4.5.1     交叉编译器 2.linux-3.5-tiny4412    ...

  7. linux下D盘(适用于U盘、硬盘等一切移动存储设备)策略(比格式化猛,因为是不可恢复!)

    关于这样的资料,在百度上还是比较少的,今天就共享出来,在电脑主机上插上你的U盘,输入以下命令: dd if=/dev/zero of=/dev/sdb  bs=1024 count=102400   ...

  8. 记——加快gradle 构建速度的经验

    Gradle作为一个新的构建系统,无疑在灵活,扩展,跨平台等各方面都表现得非常优秀,然而,它也有一点备受吐槽,就是速度慢.以下为本人使用gradle过程中,几次加快gradle构建速度的经验之谈. 本 ...

  9. Android热补丁技术—dexposed原理简析(手机淘宝采用方案)

    上篇文章<Android无线开发的几种常用技术>我们介绍了几种android移动应用开发中的常用技术,其中的热补丁正在被越来越多的开发团队所使用,它涉及到dalvik虚拟机和android ...

  10. hibernate链接数据库链接池c3p0配置

    [html] view plain copy <bean id="dataSourceLocal" name="dataSource" class=&qu ...