1866. 围栏刷漆

摘要
Title: 1866. 围栏刷漆
Tag: 区间合并
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

1866. 围栏刷漆

  • 题意

    见原题

  • 思路

    区间合并模板题,只需合并两个区间

  • 代码

    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
    '''
    Author: NEFU AB-IN
    Date: 2022-04-08 15:47:47
    FilePath: \ACM\Acwing\1866.py
    LastEditTime: 2022-04-08 15:47:47
    '''
    INF = int(1e9)
    L, R = -INF, -INF

    a = []
    for i in range(2):
    l, r = map(int, input().split())
    a.append([l, r])
    a.sort()

    res = 0
    for l, r in a:
    if R < l:
    if L != -INF and R != -INF:
    res += (R - L)
    L, R = l, r
    else:
    R = max(R, r)

    if L != -INF and R != -INF:
    res += (R - L)

    print(res)
使用搜索:谷歌必应百度