0
点赞
收藏
分享

微信扫一扫

Leetcode算法系列| 9. 回文数

一、题目

二、示例

三、要求

四、解题思路

五、参考代码 

# -*- coding: utf-8 -*-
'''
@File    :   2023-B-观看文艺汇演-计算演出场次.py
@Time    :   2023/12/29 18:40:26
@Author  :   mgc 
@Version :   1.0
@Desc    :   None
'''

# import os
# import re
# import sys
# import copy
# import math
# import queue
# import functools
# from queue import Queue
# from collections import Counter, defaultdict

def calculate_max_shows(N):
    
    shows = []  # 演出时间表

    # 获取演出时间表
    for _ in range(N):
        T, L = map(int, input().split())
        shows.append((T, L))

    shows.sort()  # 按开始时间排序

    max_shows = 0  # 最多能观看的演出场数
    end_time = -15  # 当前观看的演出的结束时间,初始化为-15分钟

    for show in shows:
        start_time, duration = show

        if start_time >= end_time + 15:  # 存在至少15分钟的时间间隔
            max_shows += 1
            end_time = start_time + duration

    print(max_shows)  # 输出最多能观看的演出场数

N = int(input())  # 演出场数
calculate_max_shows(N)
举报

相关推荐

0 条评论