日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

B - Average Numbers CodeForces - 134A(水题,思维)

發布時間:2023/12/15 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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(水题,思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。