Los problem solution [Valley] CF134A

题解 CF134A 【Average Numbers】


This question is a simple simulation.

To optimize the constant just about anything

Ideas:

In order not to waste time always were averaged, using a direct  S sum S is stored, each time subtracting  A _ I A I  divided by  n-- I n- - I multiplied by  1.0 . 1 . 0 Ke is already on.

On the following codes:

#include <bits/stdc++.h>
using namespace std;
int a[200001],S,b[200001],top = 0,ans;
int main() {
    int n;
    cin>>n;
    for (register int i = 1; i <= n; i++) {
        cin>>a[i];
        S += a[i];//S累加
    }
    for (register int i = 1; i <= n; i++) {
        if(a[i] == (S - a[i]) * 1.0 / (n - 1)) {//判断平均数与ai是否相等
            b[++top] = i;//标记
            ans++;//统计个数
        }
    }
    cout<<ans<<endl;
    for (register int i = 1; i <= top; i++)
        cout<<b[i]<<' ';//输出,不解释
    cout<<endl;
    return 0;
}

题目链接:https://www.luogu.org/problem/CF134A

Guess you like

Origin www.cnblogs.com/Ice-watermelon233/p/problem_ans_luogu_CF134A.html