美文网首页
Codeforces 1360B - Honest Coach

Codeforces 1360B - Honest Coach

作者: 费城的二鹏 | 来源:发表于2020-05-26 21:18 被阅读0次

    不知道什么时候能做出正宗的铁板土豆。

    翻译

    诚实的教练

    面前有 n 名运动员,运动员被从左到右编码,你知道每个运动员的能力水平,运动员 i 的能力值为 s[i]。

    你需要将运动员分成两个队伍,每队至少有一名运动员,每个运动员在且只在一个队伍里。

    你希望第一个队里最强的运动员与第二个队里最弱的运动员差距最小。

    输出两个队员能力差值的绝对值。

    输入格式

    输入整数 t,表示测试用例组数。

    每个测试用例输入两行。

    第一行,输入整数 n,表示运动员数量。

    第二行,输入 n 个整数,用空格分隔,表示运动员能力。

    输出格式

    每个测试用例输出能力差值。

    分析

    代码(PyPy3)

    # https://codeforces.com/problemset/problem/1360/B
    
    import sys
    import os
    import heapq
    
    try:
        path = "./file/input.txt"
        if os.path.exists(path):
            sys.stdin = open(path, 'r')
        # sys.stdout = open(r"./file/output.txt", 'w')
    except:
        pass
    
    t = int(input())
    
    def printd(value):
        # print(value)
        pass
    
    for _ in range(t):
        n = int(input())
        arr = list(map(int, input().split(" ")))
        arr.sort()
        result = 20000
        for i in range(1, n):
            value = arr[i] - arr[i - 1]
            if value < result:
                result = value
        print(result)
    

    更多代码尽在 https://github.com/Tconan99/Codeforces

    by 费城的二鹏 2020.05.25 长春

    相关文章

      网友评论

          本文标题:Codeforces 1360B - Honest Coach

          本文链接:https://www.haomeiwen.com/subject/kpdyahtx.html