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. windows 电脑配置信息检测

    内存条 DDR4 DDR4相比DDR3最大的区别有: 1)处理器:每次内存升级换代时,必须支持的就是处理器.Haswell-E平台的内存同IVB-E/SNB-E一样为四通道设计,DDR4内存频率原生支 ...

  2. cmake编译android平台的libPoco

    1.下载源代码,解压到POCO-1.7.8-ALL 2.从$ANDROID_NDK\cmake下复制android.toolchain.cmake AndroidNdkGdb.cmake Androi ...

  3. 题目1008:最短路径问题(最短路径问题dijkstra算法)

    题目链接:http://ac.jobdu.com/problem.php?pid=1008 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  4. sencha touch list ListPaging使用详解

    示例代码: Ext.define('app.view.message.List', { alternateClassName: 'messageList', extend: 'Ext.List', x ...

  5. 关于sizeof和strlen

    已知 char *str1="absde"; char str2[]="absde"; char str3[8]={'a',}; char ss[] = &qu ...

  6. 23种设计模式之策略模式(Strategy)

    策略模式是一种对象的行为型模式,定义一系列算法,并将每一个算法封装起来,并让它们可以相互替换.策略模式比算法独立于使用它的客户而变化,其目的是将行为和环境分隔,当出现新的行为时,只需要实现新的策略类. ...

  7. phantomjs试玩

    简单来说,phantomjs就是一个运行在node上的webkit内核,支持DOM渲染,css选择器,Canvas,SVG等,在浏览器上能做的事情,理论上,phantomjs 都能模拟做到. phan ...

  8. windows下的zookeeper安装

    先在官网下载安装包(https://www.apache.org/dyn/closer.cgi/zookeeper/),单机安装非常简单,只要获取到 Zookeeper 的压缩包并解压到某个目录如:C ...

  9. POJ-1179 Polygon (动态规划)

    Polygon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5293 Accepted: 2238 Description P ...

  10. HDU 2829 - Lawrence - [斜率DP]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2829 T. E. Lawrence was a controversial figure during ...