我是靠谱客的博主 欢呼红酒,最近开发中收集的这篇文章主要介绍B - Average Numbers CodeForces - 134A(水题,思维),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

You are given a sequence of positive integers a1, a2, …, an. Find all such indices i, that the i-th element equals the arithmetic mean of all other elements (that is all elements except for this one).

Input
The first line contains the integer n (2 ≤ n ≤ 2·105). The second line contains elements of the sequence a1, a2, …, an (1 ≤ ai ≤ 1000). All the elements are positive integers.

Output
Print on the first line the number of the sought indices. Print on the second line the sought indices in the increasing order. All indices are integers from 1 to n.

If the sought elements do not exist, then the first output line should contain number 0. In this case you may either not print the second line or print an empty line.

Examples
Input
5
1 2 3 4 5
Output
1
3
Input
4
50 50 50 50
Output
4
1 2 3 4

就是水题,从头到尾遍历加和,然后一个一个遍历就好了。这个题有很多人一开始wa了,不知道是什么情况。在判断这个是否为平均数的时候,我才用的方法不是除以一个数,而是让另一个数乘以一个数这样来判断的。因为这样可以省去小数的麻烦。可能这样就可以了。
代码如下:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

const int maxx=2e5+10;
int a[maxx];
int b[maxx];
int n;

int main()
{
	while(cin>>n)
	{
		int sum=0;
		int cnt=0;
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			sum+=a[i];
		}
		for(int i=0;i<n;i++)
		{
			if(a[i]*(n-1)==sum-a[i])
			{
				b[cnt++]=i+1;
			}
		}
		cout<<cnt<<endl;
		for(int i=0;i<cnt;i++) cout<<b[i]<<" ";
		cout<<endl;
	}
}

努力加油a啊。(o)/~

最后

以上就是欢呼红酒为你收集整理的B - Average Numbers CodeForces - 134A(水题,思维)的全部内容,希望文章能够帮你解决B - Average Numbers CodeForces - 134A(水题,思维)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(70)

评论列表共有 0 条评论

立即
投稿
返回
顶部