注意到,当我们删除一个数并加入平均数时,若总元素个数 , 则与新平均数差值最小的数必然为原平均数
具体的,若与原平均数最相近的数且不大于原平均数的数为 , 不小于原平均数的数为 ,平均数为 , 有 。
若 , 则替换完后的新平均数 。 显然有 ,所以第二次替换便只能替换 。此后同理, 同理。
若 , 则第一次替换中有两种方案,第二次则转变为上述情况,以下不过多论述。
而当总元素个数 且 时,平均数显然为 , 此时替换 , 均可,替换完后同理,此时方案数为 。
AC code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=5e5+50,mod=998244353;
int ksm(int u,int v){
int res=1;
while(v){
if(v&1) res=(res*u)%mod;
v>>=1,u=(u*u)%mod;
}
return res;
}
int n,k;
double f[maxn],mid;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>f[i],mid+=f[i];
}
sort(f+1,f+1+n),mid/=n;
int r=lower_bound(f+1,f+1+n,mid)-f,l=lower_bound(f+1,f+1+n,mid)-f-1;
if(f[r]-mid==mid-f[l]){
if(n==2) cout<<ksm(2,k)<<"\n";
else cout<<2<<"\n";
}
else cout<<1<<"\n";
return 0;
}