【USACO 2017 December Silver】My Cow Ate My Homework题解

Description
在你的历史课上,你得到了一个很长的作业。这个作业包含了N个题目(3 ≤ N ≤ 100,000),每个题目的成绩在0~10,000之间。

按照惯例,你的老师按照以下方式计算最终成绩:去掉你最低的一个成绩,然后将其余成绩的平均成绩作为最终成绩。但不幸的是,你的宠物牛“贝西”刚刚吃了前K个题目的答案!(1 ≤ K ≤ N-2)

经过你的一番解释,老师终于相信了你的故事,并且同意对你有答案的题目(没有被吃掉答案的题目)像之前一样给分——通过去掉最低的成绩(如果有多个最低成绩,则只去掉其中一个)并取剩余成绩的平均成绩。

根据这一成绩计算方案,请按升序输出所有可以使你最终成绩最高的K的值。
Input
The first line of input contains N, and the next line contains the scores on the N homework questions.
Output
Please output, one value per line, all values of K which would have earned you the maximum possible score.
Sample Input
5
3 1 9 2 7
Sample Output
2
Solution
让你失望了!
这是一道水题,不讲。

#include<cstdio>
using namespace std;
int s[100001];
int main() {
	freopen("homework.in","r",stdin);
	freopen("homework.out","w",stdout);
	int n;
	double ans=0.0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		int x;
		scanf("%d",&x);
		s[i]=s[i-1]+x;
	}
	for(int i=1;i<n-1;i++) {
		if((double)(s[n]-s[i])/(double)(n-i)>ans)
			ans=(double)(s[n]-s[i])/(double)(n-i);
	}
	for(int i=1;i<n-1;i++) {
		if((double)(s[n]-s[i])/(double)(n-i)==ans)
			printf("%d\n",i);
	}
}

猜你喜欢

转载自blog.csdn.net/MZHjr/article/details/106531496
my