Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >PTA 7-5 实验室使用排期 (25 分)

PTA 7-5 实验室使用排期 (25 分)

原创
作者头像
freesan44
修改于 2021-09-13 02:11:14
修改于 2021-09-13 02:11:14
4780
举报
文章被收录于专栏:freesan44freesan44

题目

受新冠疫情影响,当前大家的活动都必须注意保持充分的社交距离,国家实验室的使用也同样受到了严格的限制。假设规定任何一个时间点上,实验室内最多只能有 1 个人,且每个人都必须提前申请实验室的使用,只有申请被批准后才能进入。现给定一批第二天的实验室使用申请,你需要写个程序自动审批,使得能够被批准的申请数量最大化。

输入格式:

输入第一行首先给出一个正整数 N(≤2×10

3

),为申请总量。随后 N 行,每行按以下格式给出申请信息:

hh:mm:ss hh:mm:ss

其中 hh:mm:ss 表示一天内的时间点“小时:分钟:秒钟”,最早从 00:00:00 开始,最晚到 23:59:59 结束。第一个时间点为进入实验室的时间,第二个是离开时间。题目保证离开时间在进入时间之后。

注意所有时间都在一天之内。时间按 24 小时显示。

输出格式:

在一行中输出能够被批准的最大申请数量。

代码语言:txt
AI代码解释
复制
输入样例:
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
结尾无空行
输出样例:
5
结尾无空行
样例解释:
除了最后两个申请,其它都可以被批准。

解题思路

代码语言:txt
AI代码解释
复制
N = int(input())
# N = 7

def zhuanhua(input:str)->int:
    h,m,s = map(int,input.split(":"))
    res = s+m*60+h*60*60
    return res
inputList = []
for _ in range(N):
    start, end = map(zhuanhua, input().split())
    # start, end = map(zhuanhua, "18:00:01 23:07:01".split())
    inputList.append((start, end))
inputList.sort(key= lambda x:(-x[1],x[0]))
start = 0
maxEndTime = zhuanhua("23:59:59")
res = 0
# print(inputList)
for x,y in inputList:
    if y<=maxEndTime:
        maxEndTime = x
        res += 1
print(res)

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
PAT 1017 Queueing at Bank (25分) prioriry_queue
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.
vivi
2020/07/14
4270
PTA 1006 Sign In and Sign Out (25 分)
At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and locked the door on that day.
freesan44
2021/09/24
3240
最强最全面的大数据SQL面试题和答案(由31位大佬共同协作完成)
本套SQL题的答案是由许多大佬共同贡献,1+1的力量是远远大于2的,有不少题目都采用了非常巧妙的解法,也有不少题目有多种解法。本套大数据SQL题不仅题目丰富多样,答案更是精彩绝伦!
五分钟学大数据
2021/12/27
5.2K0
PTA 7-2 数字之王 (20 分)
的每个数的各位数的立方相乘,再将结果的各位数求和,得到一批新的数字,再对这批新的数字重复上述操作,直到所有数字都是 1 位数为止。这时哪个数字最多,哪个就是“数字之王”。
freesan44
2021/09/11
1540
PTA 7-5 买地攻略 (25 分)
数码城市有土地出售。待售的土地被划分成若干块,每一块标有一个价格。这里假设每块土地只有两块相邻的土地,除了开头和结尾的两块是只有一块邻居的。每位客户可以购买多块连续相邻的土地。
freesan44
2021/09/11
1430
PTA 1083 List Grades (25 分)
Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of which the grades are in a given interval.
freesan44
2021/10/05
1250
第十二届蓝桥杯软件类省赛python组
小蓝准备用这些卡片来拼一些数,他想从1开始拼出正整数,每拼一个,就保存起来,卡片就不能用来拼其它数了。
润森
2022/09/22
6770
第十二届蓝桥杯软件类省赛python组
PTA 1080 MOOC期终成绩 (25 分)
对于在中国大学MOOC(http://www.icourse163.org/ )学习“数据结构”课程的学生,想要获得一张合格证书,必须首先获得不少于200分的在线编程作业分,然后总评获得不少于60分(满分100)。总评成绩的计算公式为 G=(G
freesan44
2021/08/21
3670
荣耀 0905 秋招算法面试题解析
屏幕上会显示"1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "+" "-" "="这些按钮,用户在按了若工按钮之后,如果按了"=",则会把按"="之前的字符串作为一个算式,计算结果。
五分钟学算法
2023/09/09
6730
荣耀 0905 秋招算法面试题解析
PAT 1016 Phone Bills(模拟)
1016. Phone Bills (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, d
ShenduCC
2018/04/27
8510
7-8 阅览室 (20 分)
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
韩旭051
2019/11/08
5830
一文带你入坑JDK8的新日期时间类 LocalDate、LocalTime、LocalDateTime
参考 https://blog.csdn.net/duan196_118/article/details/111597682 https://blog.csdn.net/qq_24754061/article/details/95500209 https://xijia.blog.csdn.net/article/details/106007147
时间静止不是简史
2023/02/23
4.8K0
一文带你入坑JDK8的新日期时间类 LocalDate、LocalTime、LocalDateTime
PAT(甲级)1006.Sign In and Sign Out(25)
PAT 1141.PAT Ranking of Institutions (25 分)
lexingsen
2022/02/25
2450
PAT 1017 Queueing at Bank (模拟)
1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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.
ShenduCC
2018/04/27
7250
PTA 1026 程序运行时间 (15 分)
要获得一个 C 语言程序的运行时间,常用的方法是调用头文件 time.h,其中提供了 clock() 函数,可以捕捉从程序开始运行到 clock() 被调用时所耗费的时间。这个时间单位是 clock tick,即“时钟打点”。同时还有一个常数 CLK_TCK,给出了机器时钟每秒所走的时钟打点数。于是为了获得一个函数 f 的运行时间,我们只要在调用 f 之前先调用 clock(),获得一个时钟打点数 C1;在 f 执行完成后再调用 clock(),获得另一个时钟打点数 C2;两次获得的时钟打点数之差 (C2-C1) 就是 f 运行所消耗的时钟打点数,再除以常数 CLK_TCK,就得到了以秒为单位的运行时间。
freesan44
2021/08/21
2440
PAT 1016 Phone Bills (25分) sort() + map 逻辑较为复杂
A long-distance telephone company charges its customers by the following rules:
vivi
2020/07/14
4600
Java获取上一周、上一个月、上一年的时间
SimpleDateFormat format = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”); Calendar c = Calendar.getInstance(); 1.过去七天 c.setTime(new Date()); c.add(Calendar.DATE, - 7); Date d = c.getTime(); String day = format.format(d); System.out.println(“过去七天:”+day); 2
栗筝i
2022/12/01
1.9K0
案例解读:利用12c渐进式DASH分析"ON CPU"
墨墨导读:本文来自墨天轮读者“Anbob”供稿,分享利用12c渐进式DASH分析"ON CPU"的过程。
数据和云
2021/03/11
5650
MySQL函数大全及用法示例(三)
dayofweek(date) 返回日期date是星期几(1=星期天,2=星期一,……7=星期六,odbc标准) mysql> select dayofweek('1998-02-03');   -> 3 weekday(date) 返回日期date是星期几(0=星期一,1=星期二,……6= 星期天)。 mysql> select weekday('1997-10-04 22:23:00');   -> 5 mysql> select weekday('1997-11-05');   -> 2 dayofmonth(date) 返回date是一月中的第几日(在1到31范围内) mysql> select dayofmonth('1998-02-03');   -> 3 dayofyear(date) 返回date是一年中的第几日(在1到366范围内) mysql> select dayofyear('1998-02-03');   -> 34 month(date) 返回date中的月份数值 mysql> select month('1998-02-03');   -> 2 dayname(date) 返回date是星期几(按英文名返回) mysql> select dayname("1998-02-05");   -> 'thursday' monthname(date) 返回date是几月(按英文名返回) mysql> select monthname("1998-02-05");   -> 'february' quarter(date) 返回date是一年的第几个季度 mysql> select quarter('98-04-01');   -> 2 week(date,first) 返回date是一年的第几周(first默认值0,first取值1表示周一是 周的开始,0从周日开始) mysql> select week('1998-02-20');   -> 7 mysql> select week('1998-02-20',0);   -> 7 mysql> select week('1998-02-20',1);   -> 8 year(date) 返回date的年份(范围在1000到9999) mysql> select year('98-02-03');   -> 1998 hour(time) 返回time的小时数(范围是0到23) mysql> select hour('10:05:03');   -> 10 minute(time) 返回time的分钟数(范围是0到59) mysql> select minute('98-02-03 10:05:03');   -> 5 second(time) 返回time的秒数(范围是0到59) mysql> select second('10:05:03');   -> 3 period_add(p,n) 增加n个月到时期p并返回(p的格式yymm或yyyymm) mysql> select period_add(9801,2);   -> 199803 period_diff(p1,p2) 返回在时期p1和p2之间月数(p1和p2的格式yymm或yyyymm) mysql> select period_diff(9802,199703);   -> 11 date_add(date,interval expr type) date_sub(date,interval expr type) adddate(date,interval expr type) subdate(date,interval expr type) 对日期时间进行加减法运算 (adddate()和subdate()是date_add()和date_sub()的同义词,也 可以用运算符+和-而不是函数 date是一个datetime或date值,expr对date进行加减法的一个表 达式字符串type指明表达式expr应该如何被解释  [type值 含义 期望的expr格式]:  second 秒 seconds
哲洛不闹
2018/09/14
8880
Vue学习笔记之moment.js日期处理控件
moment可以方便的计算自然月或者自然年份,避免使用固定天数或者月份计算导致结束日期错乱问题。
Jetpropelledsnake21
2022/11/12
13.4K0
Vue学习笔记之moment.js日期处理控件
相关推荐
PAT 1017 Queueing at Bank (25分) prioriry_queue
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档