A1017 Queueing at Bank (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 (≤104) - 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

题目分析

这道题其实思路不是很难的,毕竟先做过了一个30分的类似题,思路是很相似的,需要注意的是如果到达时间不超过17:00,而完成的时间超过17:00这种情况是要计算在内的,只是我有一个疑问如果到了17:00,还没排到队的人是否应该继续等待?按常识是不会的,可是这道题目按常识来是不对的。。。我当时加了一个判断如果一个窗口的endtime大于了17:00,那么后面的客户等待时间应该是到17:00就结束了,继续等下去显然是有点傻的,因为人家已经不服务了啊,显然对于一道模拟题,我觉得这里设计的不太好啊。

这题似乎还有另一个小bug,大家可以尝试一下,如果大家忘记题目给的It is assumed that no window can be occupied by a single customer for more than 1 hour.条件,即不判断每一个人的处理过程是否超过了一个小时,这道题目依然能AC,我一开始没注意这个条件,最后一个测试点过不了以为是这里的问题,可是修改后依然过不了。最后我把之前代码都给删除掉用秒作为基本单位,而不是分(我一开始用的是分作为比较单位,比较麻烦,我怀疑最后一个点A不了和这个有点关系),A掉了,我特意把在前面判断一个每个人停留时间是否超过1个小时的代码删除,发现依然A掉了。。。这显然是测试系统忘记了这个条件,感兴趣的大家可以尝试一下。

基于上面两个原因,虽然我的思路一开就想好了,但A题的过程很不顺利,唉~

具体代码

    #include<stdio.h>
#include<stdlib.h> int endtime[105] = { 0 };
struct person
{
int sec;
int pro;
}; struct person p[10010]; int N, M;
int all_wait = 0; int cmp(const void *p, const void *q)
{
return ((struct person*)p)->sec - ((struct person*)q)->sec;
} int main(void)
{
scanf("%d %d", &N, &M);
for (int i = 0; i < N; i++)
{
int h, m, s, t;
scanf("%d:%d:%d %d", &h, &m, &s, &t);
if (t * 60 > 3600)
p[i].pro = 60 * 60;
else
p[i].pro = t * 60;
p[i].sec = h * 60 * 60 + m * 60 + s;
}
for (int i = 0; i < M; i++)
{
endtime[i] = 8 * 60 * 60;
}
int i;
qsort(p, N, sizeof(struct person), cmp);
for (i = 0; (i < N) && (p[i].sec <= 17 * 60 * 60); i++)
{
int earliest = 0;
for (int j = 0; j < M; j++)
if (endtime[j] < endtime[earliest])
earliest = j;
if (p[i].sec < endtime[earliest])
{
all_wait += endtime[earliest] - p[i].sec;
endtime[earliest] += p[i].pro;
}
else
endtime[earliest] = p[i].sec + p[i].pro;
}
if (i)
printf("%.1f", all_wait / 60.0 / i);
else
printf("0.0");
system("pause");
}

参考博客

最新文章

  1. java入门第三步之数据库连接
  2. Html5特性及简介
  3. Android之ListView&amp;ViewPager模拟新闻界面
  4. Delphi中如何将 Exe 程序或其他资料打包在内,使用时再释放使用(转)
  5. 番茄工作法和Bullet Journal笔记法
  6. NoSql数据库使用半年后在设计上面的一些心得 (转)
  7. .@RequestMapping 使用方法
  8. linux系统监控常用工具
  9. WPF换肤之八:创建3D浏览效果
  10. hdu 1559 最大子矩阵(DP)
  11. 1029. Median
  12. servlet请求编码与响应编码问题(编码不一致可能会导致乱码)
  13. 新版Eclipse打开jsp、js等为文本编辑,没有JSP Editor插件问题
  14. 计算机网络相关:应用层协议(一):DNS
  15. 服务器搭建--Linux安装erlang
  16. In MySQL, a zero number equals any string
  17. mac上查找nginx安装位置
  18. hdu 2206 IP的计算(最全的注意事项)
  19. 编译linux kernel及制作initrd ( by quqi99 )
  20. 【转载】TCP和TCP/IP的区别

热门文章

  1. Shell 变量自增实现方法
  2. Tecplot——为动画添加求解时间(翻译)
  3. Spring系列(2):Spring框架
  4. jmeter压力测试中的疑难杂症
  5. [Beta]Scrum Meeting#8
  6. 工具系列 | 如何在阿里云负载均衡上启用WS/WSS支持
  7. tensorflow 预训练模型列表
  8. gcc编译链接std::__cxx11::string和std::string的问题
  9. JS实现统一社会信用代码的效验(组织机构代码效验)
  10. 使用Flume-Taildir和rocketmq-flume与RocketMQ的结合