2031. 折叠绳子

摘要
Title: 2031. 折叠绳子
Tag: 枚举
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

2031. 折叠绳子

  • 题意

    见原题

  • 思路

    一共两种点是符合条件的:

    • 绳子的结点
    • 相邻结点的中点

    枚举所有这种点,并且判断这种点两端的点是否符合条件即可

  • 代码

    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
    '''
    Author: NEFU AB-IN
    Date: 2022-05-21 14:36:20
    FilePath: \ACM\Acwing\2031.py
    LastEditTime: 2022-05-21 14:45:12
    '''


    def check(l, r):
    i, j = l, r
    while i >= 0 and j < n:
    if a[l] - a[i] != a[j] - a[r]:
    return 0
    i -= 1
    j += 1
    return 1


    n, l = map(int, input().split())

    a = []
    for i in range(n):
    a.append(int(input()))

    a.sort()

    ans = 0
    for i in range(1, n - 1): # 备选点,结点
    if check(i, i):
    ans += 1

    for i in range(1, n): # 备选点,结点中点
    if check(i - 1, i):
    ans += 1

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