PAT 1017 Queueing at Bank[一般]
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[一般]的更多相关文章
- 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 (java中Map用法)
由PAT1017例题展开: Suppose a bank has K windows open for service. There is a yellow line in front of the ...
- 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 ...
- 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 ...
- 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 ...
- PAT甲级1017. Queueing at Bank
PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...
- 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
https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968 Suppose a bank has K w ...
- PAT (Advanced Level) 1017. Queueing at Bank (25)
简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...
随机推荐
- .net环境下的缓存技术-转载!
摘要: 介绍缓存的基本概念和常用的缓存技术,给出了各种技术的实现机制的简单介绍和适用范围说明,以及设计缓存方案应该考虑的问题(共17页) 1 概念 1.1 缓存能解决的问题 · 性 ...
- Qt编写网络中转服务器(开源)
需求1:手机端或者其他端可以对设备进行回控,并查看设备各种运行状态,接收报警推送等.2:同时支持在局域网.广域网.互联网访问,尤其是互联网访问.3:权限控制,给定账号控制授权的设备,并自动拉取设备信息 ...
- enum hack
关于占用内存的大小,enum类型本身是不占内存的,编译器直接替换.但是enum类型的变量肯定是占内存的. class A{ public: //enum类型本身不占内存 enumEnumTest{ a ...
- Repeater嵌套绑定Repeater以及内层调用外层数据
aspx: <table border=" style="margin-bottom: 5px" width="100%"> <as ...
- FTP协议的粗浅学习--利用wireshark抓包分析相关tcp连接
一.为什么写这个 昨天遇到个ftp相关的问题,关于ftp匿名访问的.花费了大量的脑细胞后,终于搞定了服务端的配置,现在客户端可以像下图一样,直接在浏览器输入url,即可直接访问. 期间不会弹出输入用户 ...
- 使用mimikatz获取和创建Windows凭据的工具和方法
Mimikatz 下载地址 https://github.com/gentilkiwi/mimikatz/releases 本地凭据破解 以管理员身份运行(拿到shell提权后) mimikatz#p ...
- python----题库(一)
1.执行 Python 脚本的两种方式 答:1.>>python ../pyhton.py 2. >>python.py #必须在首行有 #!/usr/bin/env pyth ...
- java-04-动手动脑
1String.equals()方法的实现代码 public boolean equals(Object anObject) { if (this == anObject) { return true ...
- ZJU-1003 Crashing Balloon dfs,
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3 题意(难以描述):A,B两个人从1~100选数乘起来比谁的大(不能选重复的或者 ...
- Oracle核心技术之 SQL TRACE
1.SQL TRACE说明: 参数类型 布尔型 缺省值 false 参数类别 动态 取值范围 True|false 2.类型 1)sql trace参数:alter system改变对全局进程影响,如 ...