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

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

转载于:https://www.cnblogs.com/BlueBlueSea/p/9384980.html

PAT 1017 Queueing at Bank[一般]相关推荐

  1. PAT甲级1017 Queueing at Bank:[C++题解]字符串、结构体、最小堆

    文章目录 题目分析 题目链接 题目分析 客户数据用什么存呢? 好吧,还是用结构体. 结构体里面存什么呢? 到达时间 和服务时间. 窗口怎么存呢? 将窗口的开始服务时间从小到大存,自然想到小根堆. pr ...

  2. PAT (Advanced Level) 1017 Queueing at Bank(模拟)

    题目链接:点击查看 题目大意:模拟银行服务的过程,输出每个客户的平均等待时间 题目分析:类似的银行服务模拟题,不过与之前那个题不太一样的是,这一次所需要统计的信息变少了,只需要统计一下每个客户的平均等 ...

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

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

  4. PAT甲级 1017 Queueing at Bank

    原题传送门 >>> 几个注意点: 1.凡是在17:00:00之前(包括17:00:00)到的顾客,银行都必须把它们完全服务完成.(也就是说,在这之前银行不下班). 这个设定也太迷惑了 ...

  5. 1017 Queueing at Bank (25 分)_27行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Suppose a bank has K windows open for service. There is a yellow ...

  6. 1017 Queueing at Bank (25 分) 【未完成】【难度: 中 / 知识点: 模拟】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968

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

  8. PAT Queueing at Bank(字符串处理)

    题目: 假设一家银行有 K 个服务窗口. 窗户前面有一条黄线,将等候区分为两部分. 所有客户都必须在黄线后面排队等候,直到轮到他/她服务并且有可用的窗口为止. 假定一个窗口不能被单个客户占用超过 1 ...

  9. 浙大pat 1017

    #include<iostream> #include<queue> #include<string> #include<vector> #includ ...

最新文章

  1. 欢迎参加城市大脑与智慧城市前沿趋势 主题论坛 |未来科技大讲堂 第12期
  2. PHP 读写TXT与Mysql性能测试
  3. 【学习笔记】之多项式使人头秃
  4. mysql 评论回复表设计_【数据库】评论回复表设计
  5. 记一次偶遇Adminer
  6. if test 多条件_秒懂Python编程中的if __name__ == #39;main#39; 作用和原理
  7. 郫都区计算机老师周俊老师,教师节,带你走进郫都教师背后的故事
  8. 如何打印出给定尺寸的方格_打印给定号码的表格| 8085微处理器
  9. Java 程序性能优化《第一章》Java性能调优概述 1.4小结
  10. CSS 设置表格格式
  11. php mysql memcache_php的memcache和memcached扩展区别
  12. mysql服务的注册,启动、停止、注销。 [delphi代码实现]
  13. datax源代码编译安装
  14. 【干货】神经网络SRU
  15. 使用Ant定义生成文件
  16. extjs6整合到web项目中
  17. jz2440裸机开发与分析:S3c2440代码重定位详解3---链接脚本的解析
  18. 服务器四核cpu性能排行,服务器cpu性能排行
  19. PDF书签制作的方法!
  20. RTX自动配置客户端服务器地址

热门文章

  1. 省选+NOI 第六部分 技巧与思想
  2. 小学奥数 7649 我家的门牌号 python
  3. 1982:【19CSPJ普及组】数字游戏 方法二
  4. RTX5 | 内存池04 - 共享内存用于线程之间的通讯(阻塞方式)- 使用信号量
  5. Spring Boot笔记-使用RestTemplate优雅的调用百度ORC接口
  6. Web前端笔记-2D图形平面内平移定位(two.js)
  7. QML笔记-整合C++及单例模式管理QML中控件
  8. QML学习笔记-对QML基本认识
  9. Opencv 图片缩小尺寸原理
  10. 安卓 linux 街机 dc,DC最强的街机模拟器