python难度_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 < ::: <

tn≤ 500), 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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值