1017 Queueing at Bank (25)(25 point(s))
problem
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
tip
模拟题
answer
#include<algorithm>
#include<iomanip>
#include<iostream>
#include<vector>
#include<queue>
#define INF 0x3f3f3f3f
using namespace std;
int N, K, Begin, End;
typedef struct {
int arr, begin, end, pro, wait;
}People;
vector<People> p;
queue<People> q[110];
int TranTime(string t){
int hour = 0, minute = 0, second = 0;
hour = (t[0]-'0')*10+t[1]-'0';
minute = (t[3]-'0')*10+t[4]-'0';
second = (t[6]-'0')*10+t[7]-'0';
return (hour)*60*60 + minute*60 + second;
}
bool Comp(People a, People b){
return a.arr < b.arr;
}
void Push(People &t){
int min = INF, index = 0;
bool flag = false;
for(int i = 0; i < K; i++){
if(q[i].empty()) {
index = i;
flag = true;
continue;
}
if(q[i].back().end < min && !flag) {
min = q[i].back().end;
index = i;
}
}
// cout<<index<<endl;
if(flag){
if(t.arr < Begin){
t.begin = Begin;
t.wait = Begin - t.arr;
}else{
t.begin = t.arr;
t.wait = 0;
}
t.end = t.begin + t.pro;
q[index].push(t);
}else{
if(t.arr < q[index].back().end){
t.begin = q[index].back().end;
t.wait = q[index].back().end - t.arr;
}else{
t.begin = t.arr;
t.wait = 0;
}
t.end = t.begin + t.pro;
q[index].push(t);
}
// cout<<t.arr/(3600)<<":"<<t.arr%(3600)/60<<" "<<t.begin/(3600)<<":"<<t.begin%(3600)/60<<" "<<t.end/(3600)<<":"<<t.end%(3600)/60<<" "<<t.wait/60<<" "<<t.pro/60<<" "<<endl;
}
void Pop(){
}
void PrintStatus(){
for(int i = 0; i < K; i++){
cout<<i<<endl;
for(int j = 0; j < q[i].size(); j++){
cout<<q[i].front().begin/(60*60)<<":"<<q[i].front().begin%(60*60) /60<<" "<<q[i].front().end/(60*60)<<":"<<q[i].front().end%(60*60) /60<<" "<<q[i].front().wait<<endl;
q[i].push(q[i].front());
q[i].pop();
}
cout<<endl;
}
}
int main(){
// freopen("test.txt", "r", stdin);
ios::sync_with_stdio(false);
Begin = TranTime("08:00:00");
End = TranTime("17:00:00");
cin>>N>>K;
for(int i = 0; i < N; i++){
string time;
int pro;
cin>>time>>pro;
People tp;
tp.arr = TranTime(time);
tp.pro = pro*60;
if(tp.arr > End) continue;
p.push_back(tp);
}
sort(p.begin(), p.end(), Comp);
for(int i = 0; i < p.size(); i++){
Push(p[i]);
// PrintStatus();
}
// PrintStatus();
float wait = 0.0;
for(int i = 0; i < p.size(); i++){
wait += p[i].wait / 60.0;
}
cout<<fixed<<setprecision(1)<<wait/p.size()<<endl;
return 0;
}
/*
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
*/
exprience
- 应该在30分钟内解决的一个简单模拟题,因为写代码时思考的太少而导致debug时间太长。
1017 Queueing at Bank (25)(25 point(s))的更多相关文章
- 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 ...
- PAT 1017 Queueing at Bank (模拟)
1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...
- PAT 1017 Queueing at Bank[一般]
1017 Queueing at Bank (25)(25 分)提问 Suppose a bank has K windows open for service. There is a yellow ...
- PAT甲级1017. Queueing at Bank
PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...
- MySQL5.7.25(解压版)Windows下详细的安装过程
大家好,我是浅墨竹染,以下是MySQL5.7.25(解压版)Windows下详细的安装过程 1.首先下载MySQL 推荐去官网上下载MySQL,如果不想找,那么下面就是: Windows32位地址:点 ...
- PAT 甲级 1006 Sign In and Sign Out (25)(25 分)
1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...
- 【PAT】1020 Tree Traversals (25)(25 分)
1020 Tree Traversals (25)(25 分) Suppose that all the keys in a binary tree are distinct positive int ...
- 【PAT】1052 Linked List Sorting (25)(25 分)
1052 Linked List Sorting (25)(25 分) A linked list consists of a series of structures, which are not ...
- 【PAT】1060 Are They Equal (25)(25 分)
1060 Are They Equal (25)(25 分) If a machine can save only 3 significant digits, the float numbers 12 ...
- 【PAT】1032 Sharing (25)(25 分)
1032 Sharing (25)(25 分) To store English words, one method is to use linked lists and store a word l ...
随机推荐
- 【leetcode 简单】 第一百四十六题 最长和谐子序列
和谐数组是指一个数组里元素的最大值和最小值之间的差别正好是1. 现在,给定一个整数数组,你需要在所有可能的子序列中找到最长的和谐子序列的长度. 示例 1: 输入: [1,3,2,2,5,2,3,7] ...
- MySQL练习-主外键多表查询
练习: 1.建立表关系: 请创建如下表,并创建相关约束 USE db1; CREATE TABLE class( cid INT AUTO_INCREMENT PRIMARY KEY, caption ...
- Shell基础-通配符
* - 通配符,代表任意字符 ? - 通配符,代表一个字符 # - 注释 | - 分隔两个管线命令的界定 ; - 连续性命令的界定 ~ - 用户的根目录 $ - 变量前需要加的变量值 ! - 逻辑运算 ...
- 解决Maven并行编译中出现打包错误问题的思路
解决Maven并行编译中出现打包错误问题的思路 并行构建 Maven 3.x 提供了并行编译的能力,通过执行下列命令就可以利用构建服务器的多线程/多核性能提升构建速度: mvn -T 4 clean ...
- 《区块链100问》第85集:资产代币化之对标美元USDT
USDT是Tether公司推出的对标美元(USD)的代币Tether USD.1USDT=1美元,用户可以随时使用USDT与USD进行1:1兑换.Tether公司执行1:1准备金保证制度,即每个USD ...
- MySQL实现强制查询走索引和强制查询不缓存
0.表结构如下:(包含两个索引) Create Table: CREATE TABLE `user` ( `userID` ) NOT NULL, `userCode` ) DEFAULT NULL, ...
- perl6 HTTP::UserAgent发送post
use HTTP::UserAgent; my $ua = HTTP::UserAgent.new; say 'All method:'; say $ua.^methods; my %data = : ...
- Next Permutation & Previous Permutation
Next Permutation Given a list of integers, which denote a permutation. Find the next permutation in ...
- 【驱动】USB驱动实例·串口驱动·键盘驱动【转】
转自:http://www.cnblogs.com/lcw/p/3159370.html Preface USB体系支持多种类型的设备. 在 Linux内核,所有的USB设备都使用 usb_drive ...
- jQuery插件之ajaxFileUpload(异步上传图片并实时显示,并解决onchange后ajaxFileUpload失效问题)
参考学习: 第一篇:http://www.cnblogs.com/kissdodog/archive/2012/12/15/2819025.html 第二篇:http://www.jb51.net/a ...