1017 Queueing at Bank (25)(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
(25)(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

AC:

#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct co{
int arrive;
int begn;
int serve;
int wait;
}; bool cmp( co a , co b){
return a.arrive<b.arrive;
} int main()
{
int n,k;
int hh,mm,ss,ser,sum=;
scanf("%d%d",&n,&k);
co * Co=new co[];
if(>=n||>=k){
printf("0.0");
return ;
}
int beg=*;
for(int i=;i<n;i++){
scanf("%d:%d:%d %d",&hh,&mm,&ss,&ser);
//到达是不同时到达的,
//共32400s
Co[sum].arrive=hh*+mm*+ss-beg;//转换成秒
Co[sum].serve=ser*;
if(Co[sum].arrive<)sum++;//sum表示一共有多少人。
//我的妈呀,if里的sum写成了i。。。。导致代码通不过,醉了。
}
n=sum;
sort(Co,Co+n,cmp);//按到达时间排序。
int win[k];//表示当前窗口都没人;为什么我一开始这里定义为3,一定是气懵了。。。。
fill(win,win+k,-); int no=;//还剩下多少人需要服务。
for(int tm=;no!=n;tm++){
//int tm=0;tm<32400;tm++,一开始for循环条件是这个,但是发现了问题,
//如果这样的话,就不能保证所有在17:00之前到的顾客都能服务了。
if(no==n)break;
for(int i=;i<k;i++){
if(win[i]!=-){
if(Co[win[i]].begn+Co[win[i]].serve==tm){//当前正好有结束的。
//下一位顾客进来
win[i]=-;
}
}
}
for(int i=;i<k;i++){//如果有空,那么就开始放。
if(win[i]==-&&Co[no].arrive<=tm){
Co[no].begn=tm;
win[i]=no;
no++;
if(no==n)break;
}
}
}
// for(int i=0;i<n;i++){
// printf("\n%d %d %d\n",Co[i].arrive,Co[i].begn,Co[i].serve);
// }
long long total=;
int miu=;
for(int i=;i<n;i++){
total+=(Co[i].begn-Co[i].arrive);
// if(total%60==0){
// miu+=total/60;
// total=0;
// }
}
//miu+=1.0*total/60;//在这里不会四舍五入!!!
printf("%.1f",total/60.0/n);
return ;
}
/**
2 2
8:00:05 1
12:00:00 1 **/

//对我自己醉了,通不过就是因为瞎。。心瞎。。遇到了段错误,原来是自己一开始定义数组就错了。之后还答案错误,原来是数组下标写错了。感谢牛客网,通不过的话会有样例,能根据样例去修改代码!

PAT 1017 Queueing at Bank[一般]的更多相关文章

  1. PAT 1017 Queueing at Bank (模拟)

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

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

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

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

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

  6. PAT甲级1017. Queueing at Bank

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

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

  8. PAT 甲级 1017 Queueing at Bank

    https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968 Suppose a bank has K w ...

  9. PAT (Advanced Level) 1017. Queueing at Bank (25)

    简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...

随机推荐

  1. 删除RHSA文件方法

    DEL /F /A /Q \\?\%1RD /S /Q \\?\%1新建一个批处理文件,包含上面两行代码,然后将要删除的文件拖放进里面就OK!

  2. Android ADB命令?这一次我再也不死记了!【简单说】

    https://www.jianshu.com/p/56fd03f1aaae adb的全称为Android Debug Bridge.是android司机经常用到的工具.但是问题是那么多命令写代码已经 ...

  3. sencha touch tpl 实现按钮功能

    js如下: Ext.define('app.view.message.Info', { alternateClassName: 'messageInfo', extend: 'Ext.Containe ...

  4. IOS控制系统手势返回

    self.navigationController.interactivePopGestureRecognizer.enabled = YES; //手势返回的代理,如果自定义了leftButtonI ...

  5. 如何使QLineEdit禁止编辑

    在写程序的时候喜欢使用QLineEdit,用来显示打开文件的路径.但是很不喜欢被编辑.那么要怎么设置不可编辑呢. (1)调用lineEdit->setEnabled(False) #不可编辑了 ...

  6. python操作数据库PostgreSQL

    1.简述 python可以操作多种数据库,诸如SQLite.MySql.PostgreSQL等,这里不对所有的数据库操作方法进行赘述,只针对目前项目中用到的PostgreSQL做一下简单介绍,主要包括 ...

  7. pandas 数据类型转换

    数据处理过程的数据类型 当利用pandas进行数据处理的时候,经常会遇到数据类型的问题,当拿到数据的时候,首先需要确定拿到的是正确类型的数据,一般通过数据类型的转化,这篇文章就介绍pandas里面的数 ...

  8. 托管调试助手 "DisconnectedContext":“上下文 0xf20540 已断开连接... 请确保在应用程序全部完成 RuntimeCallableWrapper (表示其内部的 COM 组件)之前,所有 COM 上下文/单元/线程都保持活动状态并可用于上下文转换

    最近做一个winForm的小工具,用到了 ManagementObjectSearcher/ManagementClass 和 WndProc ,涉及到对 移动设备的检测. 窗体加载时会执行一个 Re ...

  9. 计蒜客 30999 - Sum - [找规律+线性筛][2018ICPC南京网络预赛J题]

    题目链接:https://nanti.jisuanke.com/t/30999 样例输入258 样例输出814 题意: squarefree数是指不含有完全平方数( 1 除外)因子的数, 现在一个数字 ...

  10. python面向对象高级:定制类

    Python的class中还有许多这样有特殊用途的函数,可以帮助我们定制类. 比如: __str__ 与__repr____iter____getitem____call__ __str__ 与__r ...