【PAT甲级】1017 Queueing at Bank (25 分)
题意:
输入两个正整数N,K(N<=10000,k<=100)分别表示用户的数量以及银行柜台的数量,接下来N行输入一个字符串(格式为HH:MM:SS)和一个正整数,分别表示一位用户到达银行的时间以及该用户占用银行资源的时间,求用户的平均等待时间。(当一位用户早于早晨八点到达银行不开门,他需要等待,当一位用户晚于下午五点到达银行关门,该用户不计入等待时间计算)【答案保留一位小数】
AAAAAccepted code:
#include<bits/stdc++.h>
using namespace std;
string s;
typedef struct{
int t,x;
}stct;
stct user[];
bool cmp(stct a,stct b){
if(a.x!=b.x)
return a.x<b.x;
return a.t<b.t;
}
int line[];
int main(){
double sum=;
int n,k;
cin>>n>>k;
for(int i=;i<=n;++i){
cin>>s>>user[i].t;
int x=;
x+=(s[]-'')*;
x+=(s[]-'')*;
x+=(s[]-'')*;
x+=(s[]-'')*;
x+=(s[]-'')*;
x+=s[]-'';
user[i].x=x;
user[i].t*=;
if(user[i].x<*){
sum+=*-user[i].x;
user[i].x=*;
}
}
sort(user+,user++n,cmp);
int cur=;
int num=;
for(int i=;i<=k;++i){
if(i>n)
break;
num=i;
line[i]=user[i].x+user[i].t;
cur=min(cur,line[i]);
}
for(int i=k+;i<=n;++i){
if(user[i].x>*)
break;
num=i;
sum+=max(,cur-user[i].x);
for(int j=;j<=k;++j)
if(line[j]==cur){
if(cur<user[i].x)
line[j]=user[i].x+user[i].t;
else
line[j]+=user[i].t;
break;
}
cur=;
for(int j=;j<=k;++j)
cur=min(cur,line[j]);
}
sum/=num;
sum/=;
printf("%.1f",sum);
return ;
}
【PAT甲级】1017 Queueing at Bank (25 分)的更多相关文章
- 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
PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...
- PAT 甲级 1017 Queueing at Bank
https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968 Suppose a bank has K w ...
- 1017 Queueing at Bank (25 分)
Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...
- PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)
1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the ...
- PAT 甲级 1083 List Grades (25 分)
1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...
- PAT甲级——1130 Infix Expression (25 分)
1130 Infix Expression (25 分)(找规律.中序遍历) 我是先在CSDN上面发表的这篇文章https://blog.csdn.net/weixin_44385565/articl ...
- PAT 甲级 1074 Reversing Linked List (25 分)(链表部分逆置,结合使用双端队列和栈,其实使用vector更简单呐)
1074 Reversing Linked List (25 分) Given a constant K and a singly linked list L, you are supposed ...
- PAT 甲级 1086 Tree Traversals Again (25分)(先序中序链表建树,求后序)***重点复习
1086 Tree Traversals Again (25分) An inorder binary tree traversal can be implemented in a non-recu ...
随机推荐
- SOA架构设计
架构是—套构建系统的准则,通过这套准则,把—个复杂的系统划 分为一套更简单的子系统的集合,这些子系统之间保持相互独立,并与 整个系统保持一致,而且每—个子系统还可以继续细分下去,从而构成 —个企业级架 ...
- python代码在linux终端中执行报错:Unable to init server: Could not connect: Connection refused
python代码在linux终端中执行时报错: Unable to init server: Could not connect: Connection refused Unable to init ...
- 吴裕雄 PYTHON 人工智能——基于MASK_RCNN目标检测(4)
import os import sys import random import math import re import time import numpy as np import tenso ...
- Android学习07
自定义Dialog 创建一个Java类CustomDialog继承Dialog. package com.example.helloworld.widget; import android.app.D ...
- windows C++ 网络编程
转载:https://blog.csdn.net/yao_hou/article/details/91400832 https://blog.csdn.net/Ctrl_qun/article/li ...
- 【C语言】找出1000以内所有的素数
#include<stdio.h> int main() { int i, j, t; ; i <= ; i++) { ; ; j < i; j++) { ) { t = ; ...
- 4 中文乱码 selenium的使用
# 中文乱码 #处理中文乱码 import requests from lxml import etree from urllib import request url = 'http://pic.n ...
- SQL表名,应该用表对应资源对象的复数形式还是单数形式
原文:http://blog.csdn.net/lizeyang 问题 SQL表名,应该用表对应资源对象的复数形式还是单数形式.例如一个用户表,表名是用user还是users更合适呢? 精华回答 ...
- 在C中测试函数运行时间
#include <stdio.h> #include <time.h> #include <math.h> clock_t start, stop; //cloc ...
- 【代码学习】PYTHON 抛出异常
class ShortInputException(Exception): '''你定义的异常类.''' def __init__(self, length, atleast): Exception. ...