zoukankan      html  css  js  c++  java
  • 2021年春季PAT甲级真题7-2

    7-2 Lab Access Scheduling (25 分)

     

    Nowadays, we have to keep a safe social distance to stop the spread of virus due to the COVID-19 outbreak. Consequently, the access to a national lab is highly restricted. Everyone has to submit a request for lab use in advance and is only allowed to enter after the request has been approved. Now given all the personal requests for the next day, you are supposed to make a feasible plan with the maximum possible number of requests approved. It is required that at most one person can stay in the lab at any particular time.

    Input Specification:

    Each input file contains one test case. Each case starts with a positive integer N (2×103), the number of lab access requests. Then N lines follow, each gives a request in the format:

    hh:mm:ss hh:mm:ss
     

    where hh:mm:ss represents the time point in a day by hour:minute:second, with the earliest time being 00:00:00 and the latest 23:59:59. For each request, the two time points are the requested entrance and exit time, respectively. It is guaranteed that the exit time is after the entrance time.

    Note that all times will be within a single day. Times are recorded using a 24-hour clock.

    Output Specification:

    The output is supposed to give the total number of requests approved in your plan.

    Sample Input:

    7
    18:00:01 23:07:01
    04:09:59 11:30:08
    11:35:50 13:00:00
    23:45:00 23:55:50
    13:00:00 17:11:22
    06:30:50 11:42:01
    17:30:00 23:50:00
     
    结尾无空行

    Sample Output:

    5
     
    结尾无空行

    Hint:

    All the requests can be approved except the last two.

    作者
    陈翔
    单位
    浙江大学
    代码长度限制
    16 KB
    时间限制
    200 ms
    内存限制
    64 MB
    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=10010;
    struct student{
        int h1,m1,s1;
        int entime;
        int h2,m2,s2;
        int outime;
    }stu[maxn];
    bool cmp(student s1,student s2){
        if(s1.outime==s2.outime){
            return s1.entime>s2.entime;
        }
        else{
            return s1.outime<s2.outime;
        }
    }
    int main(){
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d:%d:%d",&stu[i].h1,&stu[i].m1,&stu[i].s1);
            stu[i].entime=stu[i].h1*60*60+stu[i].m1*60+stu[i].s1;
            scanf("%d:%d:%d",&stu[i].h2,&stu[i].m2,&stu[i].s2);
            stu[i].outime=stu[i].h2*60*60+stu[i].m2*60+stu[i].s2;
        }
        sort(stu,stu+n,cmp);
        int sum=1;
        int nowpoint=0;
        for(int i=1;i<n;i++){
            if(stu[i].entime>=stu[nowpoint].outime){
                sum++;
                nowpoint=i;
            }
        }
        printf("%d
    ",sum);
        return 0;
    }
  • 相关阅读:
    RabbitMQ指南之一:"Hello World!"
    Java8新特性之五:Optional
    Java8新特性之四:接口默认方法和静态方法
    Java8新特性之三:Stream API
    Java8新特性之二:方法引用
    Notepad++编辑器——Verilog代码片段和语法检查
    数电(5):半导体存储电路
    数电(4):组合逻辑电路
    DDR3_新版(1):IP核调取和官方例程仿真
    数电(2):逻辑代数的基本定理
  • 原文地址:https://www.cnblogs.com/dreamzj/p/15239447.html
Copyright © 2011-2022 走看看