首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

PAT甲级-1017 Queueing at Bank (25分)

  • 24-03-03 00:43
  • 4689
  • 7736
blog.csdn.net

点击链接PAT甲级-AC全解汇总

题目:
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 (≤10​4​​ ) - 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

Sample Output:

8.2
  • 1

题意:
银行八点开门,下午五点关门,关门之前所有来的人都会处理!!那怕都已经到第二天了,照样会处理完!最后一个case的考点!
输入的是到达时间和需要处理的时间,计算所有人等待的平均值。
没有考察0人的情况,所以输出的时候没必要判断cnt是否为0,不过最好还是写一下养成习惯。

思路是把所有时间用秒表示,这样方便多了。本来还以为我真是个机灵鬼,写完查了下其他大佬也都是这样处理的…

不过我有个不理解的地方是为什么输入的时候如果发现这个人超过五点到达直接不计入统计的话,case0 1会错误,这是什么原因呢?好在一开始我是在统计的时候做的判断。

我的代码:

#include
using namespace std;

class Person{
public:
    Person(int a,int b):arrive_(a),time_need_(b){}
    int arrive_;
    int time_need_;
};

bool cmp(Person a,Person b)
{
    return a.arrive_<b.arrive_;
}

int main()
{
    int N,W,sum_wait=0,sum_cnt=0;
    cin>>N>>W;
    int widows[W]={0};
    vector<Person>persons;
    for(int i=0;i<W;i++)widows[i]=8*3600;
    for(int i=0;i<N;i++)
    {
        int hh,mm,ss,time_need;
        scanf("%d:%d:%d %d",&hh,&mm,&ss,&time_need);
        int arrive=hh*3600+mm*60+ss;
//        if(arrive>17*3600)continue;//这里判断的话case0 1会报错
        if(time_need>60)time_need=60;
        Person t(arrive,time_need*60);
        persons.push_back(t);
    }
    sort(persons.begin(),persons.end(),cmp);
    for(int i=0;i<N;i++)
    {
        //找窗口时间最小的
        int min_time=240*3600,index=0;
        for(int i=0;i<W;i++)
        {
            if(min_time>widows[i])
            {
                min_time=widows[i];
                index=i;
            }
        }
        if(persons[i].arrive_>17*3600)continue;
        if(persons[i].arrive_<min_time)//需要等
        {
            sum_wait+=min_time-persons[i].arrive_;
            widows[index]+=persons[i].time_need_;
        }
        else
        {
            widows[index]=persons[i].arrive_+persons[i].time_need_;
        }
        sum_cnt++;
    }

    printf("%.1f\n",1.0*sum_wait/60/sum_cnt);//case没有考察对0人的情况
    return 0;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
注:本文转载自blog.csdn.net的邂逅模拟卷的文章"https://blog.csdn.net/qq_34451909/article/details/105267812"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top