CF——Average Numbers

Average Numbers
Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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.

Sample Input

Input
5
1 2 3 4 5
Output
1
3 
Input
4
50 50 50 50
Output
4
1 2 3 4 
 
    
题解:给出n个正整数,从第一个数开始遍历,若第i个数等于其他数之和的平均数,计数器加1,最后,输出符合条件的个数以及按照遍历顺序输出该数的序号,要注意的是,整数的序号从1开始算起。
 
    
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int shu[200000],sh[200000];

int main()
{
    int n,i,j,k;
    int sum = 0;
    scanf("%d",&n);
    for(i = 0; i<n; i++)
    {
        scanf("%d",&shu[i]);
        sum = sum + shu[i];
    }
    int num = 0,mm,nn;
    j = 0;
    for(i = 0; i<n; i++)
    {
        mm = sum - shu[i];
        nn = (n-1) * shu[i];
        if(mm == nn)
        {
            num++;
            sh[j++] = i+1;
        }
    }
    printf("%d\n",num);
    if(num == 0)
        printf("\n");
    else
    {
        for(i = 0;i<j;i++)
        {
            if(i == 0)
                printf("%d",sh[i]);
            else
                printf(" %d",sh[i]);
        }
        printf("\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值