课前分析

感觉和1016差不多, 就模拟一下几个队列, 有空位立即插入并计算等待时间, 没空位计算最早处理完的用户的离去时间,并更新为当前时间等等。
(1) vector a(10); //定义了10个整型元素的向量(尖括号中为元素类型名,它可以是任何合法的数据类型),但没有给出初值,其值是不确定的。
(2)vector a(10,1); //定义了10个整型元素的向量,且给出每个元素的初值为1
(3)vector a(b); //用b向量来创建a向量,整体复制性赋值
(4)vector a(b.begin(),b.begin+3); //定义了a值为b中第0个到第2个(共3个)元素
(5)int b[7]={1,2,3,4,5,9,8};vector a(b,b+7); //从数组中获得初值


题目

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


题解

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct node{int come,time;
}customer;
bool cmp(node a,node b){return a.come<b.come;
}int main(){int n,k;scanf("%d %d",&n,&k);vector <node> cus;for(int i=0;i<n;i++){int hh,mm,ss,time;scanf("%d:%d:%d %d",&hh,&mm,&ss,&time);int cometime=hh*3600+mm*60+ss;if(cometime>61200) continue;customer={cometime,time*60};cus.push_back(customer);}sort(cus.begin(),cus.end(),cmp);vector<int> window(k,28800);//完成任务时间,初始为8小时的秒钟数double res=0.0;for(int i=0;i<cus.size();i++){//每个人每个人地找位置int tempindex=0,minfinish=window[0];for(int j=1;j<k;j++){//每个人每次在三个位置中找到最早结束的位置if(minfinish>window[j]){minfinish=window[j];tempindex=j;}}//找到位置后再操作,将窗口结束时间更新if(window[tempindex]<=cus[i].come){window[tempindex]=cus[i].come+cus[i].time;}else {res+=window[tempindex]-cus[i].come;window[tempindex]+=cus[i].time;}}//人数不能为0if(cus.size()==0){printf("0.0");  }elseprintf("%.1f",res/60.0/cus.size());return 0;
}

PAT甲级1017 (模拟排序)相关推荐

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

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

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

  3. PAT 甲级-入门模拟

    阅读原文 当时准备 PAT 竞赛时候,买了本<算法笔记>,书中将题型进行分类,是我最系统的一次算法学习,对题型判断.解题思路都有了新的认知,本篇文章主要记录当时刷的入门模拟题,算是比较简单 ...

  4. 【PAT甲级 vector string排序】1047 Student List for Course (25 分) 含别人的做法

    题目 样例输出 1 4 ANN0 BOB5 JAY9 LOR6 2 7 ANN0 BOB5 FRA8 JAY9 JOE4 KAT3 LOR6 3 1 BOB5 4 7 BOB5 DON2 FRA8 J ...

  5. PAT甲级 1017 Queueing at Bank

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

  6. 浙大PAT甲级-1017

    银行队列: (却没用到队列) #include <iostream> #include <string> #include <algorithm> #include ...

  7. PAT 甲级-算法初步

    阅读原文 接上一篇 PAT 甲级-入门模拟 ,自我感觉这部分才是真正的算法入门,对基础的数据结构提供了很好的类型题进行匹配练习 包括分类:排序.散列.贪心.二分.双指针.打表.递推 排序 思想解释 排 ...

  8. 【PAT甲级】字符串处理及进制转换专题

    目录 字符串处理 PAT甲级 1001 A+B Format (20 分) PAT甲级1005 Spell It Right (20 分) PAT甲级1035 Password (20 分) PAT甲 ...

  9. PAT甲级1052 Linked List Sorting:[C++题解]链表排序

    文章目录 题目分析 题目链接 题目分析 题意:给定数据(里面有不构成链表的数据,若是,则跳过),是链表的构成链表.然后根据数值大小重新排序,构成新的链表. 分析:用数组模拟链表,先建立链表.遍历链表, ...

最新文章

  1. 阿里巴巴为什么不建议直接使用Async注解?
  2. keepalived打造mysql主主高可用
  3. hdu4403暴力搜索
  4. linux rs232触摸屏驱动程序,Linux下的触摸屏驱动
  5. struts2文件上传中,如何限制上传的文件类型
  6. 老码农:这段代码绝了,切勿模仿!
  7. emlog-FLY主题模板1.4版本免费完全开源
  8. 中英文对照 —— 几何(数学)
  9. Mysql 锁定 读情况
  10. Axure| .rp的文件怎么转化为.rplib
  11. Java 聊天室实现
  12. HJ212国家环保标准的数据上报-专用智能网关IGT-SER
  13. python求解一元二次方程考虑复数_Python学习笔记:求解一元二次方程
  14. 智能客服搭建(2) - MRCP Server ASR插件开发
  15. 关闭 C4996 警告(_CRT_SECURE_NO_DEPRECATE)方法
  16. 微信小程序的数据绑定
  17. 幸福公开课字幕 中英文全
  18. numpy中的arange函数
  19. XCTF Leaking
  20. 教商家们如何设置一个在线的转盘抽奖活动!

热门文章

  1. plsa java代码_LDA主题聚类学习小结
  2. python 批量重命名文件_Python批量重命名文件的方法
  3. 物体运动到一个点停止_教科版五年级上册第四单元运动和力复习要点
  4. java中的递归问题_java 递归问题
  5. Qt connect()的第五种重载[=](){}
  6. C++表达式:if 语句
  7. LARGE_INTEGER类型和QueryPerformanceFrequency()
  8. SendMessageTimeOut函数使用方法
  9. 一起来梳理JVM知识点
  10. 黑客攻击公司化:网络犯罪也有商业模式也有CEO