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. 服务端技术进阶(六)Ant和Maven的作用是什么?两者之间功能、特点有哪些区别?

    服务端技术进阶(六)Ant和Maven的作用是什么?两者之间功能.特点有哪些区别? Ant和Maven都是基于Java的构建(build)工具.理论上来说,有些类似于(Unix)C中的make ,但没 ...

  2. iOS和OS X中的bundle

    bundle也可以称之为包(package). 它在iOS和OS X中实际为一个文件夹但却当成单独的文件来对待. 每一个app都有一个bundle,并且你可以通过在xxx.app图标上右击鼠标然后选择 ...

  3. ERP-非财务人员的财务培训教(一.一)------基本会计知识

    一.基本会计知识 第一节 会计是企业的语言 反映企业经济状况的两组会计语言词汇 四个层次的会计语言规则 财务会计报告的组成 会计语言要素 会计工作主要是把企业杂乱的会计数据归纳整理,加工编制成有用的财 ...

  4. "《算法导论》之‘线性表’":基于静态分配的数组的顺序表

    首先,我们来搞明白几个概念吧(参考自网站数据结构及百度百科). 线性表 线性表是最基本.最简单.也是最常用的一种数据结构.线性表中数据元素之间的关系是一对一的关系,即除了第一个和最后一个数据元素之外, ...

  5. DBUS基础知识

    转:http://www.cnblogs.com/wzh206/archive/2010/05/13/1734901.html DBUS基础知识 1.  进程间使用D-Bus通信 D-Bus是一种高级 ...

  6. java--加强之 Java5的泛型

    转载请申明出处:http://blog.csdn.net/xmxkf/article/details/9944389 36.入门泛型的基本应用 体验泛型: Jdk1.5以前的集合类中存在什么问题? A ...

  7. word search(二维数组中查找单词(匹配字符串))

    Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...

  8. merge intervals(合并间隔)

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  9. 检查Json格式工具

    在线JSON校验格式化工具(Be JSON) 地址:http://www.bejson.com/

  10. JavaScript 跨域之 POST 实现。

    javascript 跨域是一个很常见的问题,其中 jsonp 是一个最常用的手段,但是 jsonp 只支持 get,不支持 post,所以如果想通过 jsonp 来 post 一些数据,就头大了. ...