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");
}

参考博客

PTA A1017的更多相关文章

  1. 浙大PTA - - 堆中的路径

    题目链接:https://pta.patest.cn/pta/test/1342/exam/4/question/21731 本题即考察最小堆的基本操作: #include "iostrea ...

  2. 浙大PTA - - File Transfer

    题目链接:https://pta.patest.cn/pta/test/1342/exam/4/question/21732 #include "iostream" #includ ...

  3. ERROR<53761> - Plugins - conn=-1 op=-1 msgId=-1 - Connection Bind through PTA failed (91). Retrying...

    LDAP6.3在DSCC控制台启动实例完成,但是操作状态显示“意外错误”,查看日志如下: 04/May/2016:21:10:39 +0800] - Sun-Java(tm)-System-Direc ...

  4. PTA中提交Java程序的一些套路

    201708新版改版说明 PTA与2017年8月已升级成新版,域名改为https://pintia.cn/,官方建议使用Firefox与Chrome浏览器. 旧版 PTA 用户首次在新版系统登录时,请 ...

  5. PTA分享码-Java

    主要用于Java语法练习,非竞赛类题目.   1. Java入门          959dbf0b7729daa61d379ec95fb8ddb0   2. Java基本语法   23bd8870e ...

  6. C语言第一次实验报告————PTA实验1.2.3内容

    一.PTA实验作业 题目1.温度转换 本题要求编写程序,计算华氏温度100°F对应的摄氏温度.计算公式:C=5×(F−32)/9,式中:C表示摄氏温度,F表示华氏温度,输出数据要求为整型. 1.实验代 ...

  7. PTA题---求两个有序序列中位数所体现的思想。

    ---恢复内容开始--- 近日,在做PTA题目时,遇到了一个这样的题,困扰了很久.题目如下:已知有两个等长的非降序序列S1, S2, 设计函数求S1与S2并集的中位数.有序序列A​0​​,A​1​​, ...

  8. 第十四,十五周PTA作业

    1.第十四周part1 7-3 #include<stdio.h> int main() { int n; scanf("%d",&n); int a[n]; ...

  9. 第七周PTA作业

    第一题: #include<stdio.h> int main() { ; ; ){ sum=sum+i; i++; } printf("sum = %d\n",sum ...

随机推荐

  1. Foxmail: 错误信息::ssl连接错误, errorCode: 5,各种解决方案的大杂烩。

    1.  收件数据过多,删除部分邮件可解决 我尝试失败,在foxmail把收件箱全部删完了没解决. 2.  网上最常见的解决方法 https://help.foxmail.com/cgi-bin/hel ...

  2. [POI2008]PER-Permutation

    [POI2008]PER-Permutation 带重复的康托展开! 根本不需要中国剩余定理就可以A掉! 看完题面你会惊人地发现这好像一个康托展开!(显然是不同的啦) 首先我们来看康托展开这个东西在数 ...

  3. 东芝300D粉盒清零

    东芝300D粉盒清零 1:打开前盖 2:按"OK"键3秒,等 显示 "更换硒鼓"(注:不用选 是/否,直接进入第3步) 3:按"启用"键 4 ...

  4. uniapp - 更改项目生成模板、页面

    每次生成项目目录都需要删除一些再添加太麻烦了,就想着能不能修改一下模板 - 当然自定义模板也能实现 好了,被我找到了. 修改以后源文件名称和格式覆盖回去即可,重新启动hbuilderx 这里可以修改e ...

  5. Nexus Repository Manager OSS 3.x 安装配置

    前言想要使用maven搭建项目,但是国内的网络环境可以想象,还有公司自己开发的jar包等问题,所以需要搭建一个maven的私服,这样便于管理. 找了一些教程,顺便记下来,当做笔记. 本文以Window ...

  6. Win7下msys64安装mingw工具链

    1. 安装msys64 安装到指定目录, 例如C:\msys64 2. 命令行更新 运行msys2.exe打开命令行窗口, 执行命令 pacman -Syuu 3. 修改安装源 进入msys64/et ...

  7. arcpy地理处理工具案例教程-将细碎图斑按相同属性或相近属性合并相邻图斑

    arcpy地理处理工具案例教程-将细碎图斑按相同属性或相近属性合并到相邻图斑 商务合作,科技咨询,版权转让:向日葵,135-4855_4328,xiexiaokui#qq.com 目的:针对存在的细碎 ...

  8. jetty源码下载

    jetty下载地址:https://www.eclipse.org/jetty/download.html Release         9.4.20.v20190813 .zip .tgz api ...

  9. python快速搭建http服务

    在Windows 7/10或Ubuntu上可以通过python2.x或python3.x来快速搭建一个简单的HTTP服务器. 如果python为2.x,则可执行:$ python -m SimpleH ...

  10. odoo开发学习「目录」

    目录: 一.odoo介绍(发源 版本 ERP对比 优势劣势 应用场景 发展情况 社区介绍) 二.odoo设计思想 三.odoo自带模块 四.odoo开发前准备(python基础) 五.odoo环境搭建 ...