版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/YandiLu/article/details/82527316
修改成绩
时间限制:C/C++语言 1000MS;其他语言 3000MS 内存限制:C/C++语言 65536KB;其他语言 589824KB
题目描述:
华老师的n个学生参加了一次模拟测验,考出来的分数很糟糕,但是华老师可以将成绩修改为[0,100]中的任意值,所以他想知道,如果要使所有人的成绩的平均分不少于X分,至少要改动多少个人的分数?
输入
第一行一个数T,共T组数据(T≤10)
接下来对于每组数据:
第一行两个整数n和X。(1≤n≤1000, 0≤X≤100)
第二行n个整数,第i个数Ai表示第i个学生的成绩。(0≤Ai≤100)
输出
共T行,每行一个整数,代表最少的人数。
样例输入
2
5 60
59 20 30 90 100
5 60
59 20 10 10 100
样例输出
1
2
Hint
对于第一组数据,将59改成60即可
#多行输入
x = list(map(int,input().split()))
y = []
while x != []:
y.append(x)
x = list(map(int,input().split()))
for i in range(1,len(y)-1,2):
temp = y[i]
score = y[i+1]
sub = temp[0] * temp[1] - sum(score)
score_100 = [100 - i for i in score]
desc_100 = sorted(score_100, reverse = True)
subtotal = desc_100[0]
a = 1
for i in range(1,len(desc_100)):
if sub>subtotal:
subtotal = subtotal + desc_100[i]
a += 1
else:
break
print(a)
对于Python的多行输入一直不知道怎么写,只会写成这样了。
初学编程,如若有错,请指正,共同学习,谢谢!