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)/~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值