• python 难度分割


    对于每个问题,都有一个难度分数di,它是一个正数。 Jagger希望学生从最简单到最难解决问题,因此这些问题按照其难度分数的升序排列。
    难度差距定义为任意两个连续问题之间的难度分数之差。 贾格尔要最小化最大难度差距。 因此,他决定添加一个新问题。 可以将新问题设计为具有任何正数的难度分数,并且Jagger可以将其添加到问题列表中的任何位置。 新列表中的难度分数也应该增加。
    Jagger想知道最小的最大难度差距是多少。

    Input
    For this problem there are multiple test cases. The first line contains a single
    integer T (1 T 100) indicates the number of test cases. You are suggested to
    write a loop to deal with different test cases.
    Each test case consists of two lines. For each test case:
    The first line contains one integer n(2 n 200), which is the number of
    problems.
    The second line contains n sorted integers t1; t2; :::; tn (0 < t1 < t2 < t3 < ::: <
    tn500), which is the difficulty score for each problem.
    Output
    For each case, output the maximum possible number of problems.
    Sample Input 1
    33
    3 5 10
    4
    5 6 20 22
    2
    1 10
    Sample Output 1
    375

    思路:找到最大间距然后除以2(向上取整),但是没有完事,除以2得到的数不一定是当前最大间隔,原来的第二大间隔可能比那个平分后的要大了。

    python代码:

    T= int(input())
    
    for t_ in range(T):
        n= int(input())
        t= list(map(int, input().split()))
        if len(t) == 1:
            print(0)
            continue
        a = []
        for i in range(1,len(t)):
            diff= t[i]-t[i-1]
            a.append(diff)
    
        a.sort(reverse=True)
    
        maxd = a[0]
        max2= a[1]
        # if(maxd==1):
        #     print(2)
        ans= int((maxd+1)/2)
    
        if ans> max2:
            print(ans)
        else:
            print(max2)
    

      

  • 相关阅读:
    js代码与html代码分离示例
    day24_Nginx学习笔记
    bookStore商城开发文档
    API Management Architecture Notes
    Taking A Fresh Look At What Open Source API Management Architecture Is Available
    使用API Gateway
    Qcon2017实录|Service Mesh:下一代微服务
    聊聊 API Gateway 和 Netflix Zuul
    项目长期运维中产生的一些问题
    忆情天书的由来
  • 原文地址:https://www.cnblogs.com/zhumengdexiaobai/p/13971677.html
Copyright © 2020-2023  润新知