标签:Arts NIO Particle 蔚来 ll 样例 particles joule energy
问题描述
In a confined NIO space, there are nnn NIO particles, the iii-th of which has aia_iai joule energy. The NIO particles are very special as they keep colliding with each other randomly. When one particle carrying energy aaa joule collides with another particle carrying energy bbb joule, they will be annihilated and produce two new particles carrying the energy of a AND b and a OR b respectively. Here AND and OR mean bitwise AND and OR operation respectively.
The variance of the energy of these particles is obviously not decreasing, but
unfortunately, the space here is too small for the author to write down his
proof. After enough time the variance of the energy of these particles
converges to a stable value. Can you find this value?
The variance of n numbers is defined as
follows.
输入格式
The first line contains an integer n (2≤n≤105), indicating the number of particles.
The second line contains nnn integers a1,a2,…,an (0≤ai<215),
indicating the enegery of the particles.
输出格式
Output a irreducible fraction a/b (b>0) in the form of a/b that represents the answer. You should ensure that gcd(a,b)=1 or when a=0, b should be 1.
样例输入
5
1 2 3 4 5
样例输出
54/5
提示
Warm tip: Please note the use of data types.
题解
模拟样例可知最后方差不变时,任意两个数进行计算都不会使序列发生改变
将样例所给数字全部转换成二进制,可以发现,最后所有数字不再改变时,所有的1都被尽可能移到一起
考虑统计二进制下1和0的个数,将1尽可能的移到一起,即可生成最后不再改变的序列,答案即为该序列的方差
1 #include <cstdio> 2 #define ll long long 3 int n,a[100005],cnt[20]; 4 ll b[100005],sum,m,ans; 5 ll gcd(ll x,ll y) 6 { 7 return y?gcd(y,x%y):x; 8 } 9 int main() 10 { 11 int i,j,k; 12 scanf("%d",&n); 13 for (i=1;i<=n;i++) 14 { 15 scanf("%d",&a[i]); 16 for (k=0;k<15;k++) 17 { 18 if ((1ll<<k)&a[i]) 19 cnt[k]++; 20 } 21 } 22 ll x,s=0; 23 for (i=1;i<=n;i++) 24 { 25 for (j=0;j<=19;j++) 26 { 27 if (cnt[j]) 28 b[i]+=(1ll<<j), 29 cnt[j]--; 30 } 31 sum+=b[i]; 32 s+=b[i]*b[i]; 33 } 34 ans=s*n-sum*sum; 35 x=gcd(ans,1ll*n*n); 36 printf("%lld/%lld",ans/x,1ll*n*n/x); 37 return 0; 38 }
标签:Arts,NIO,Particle,蔚来,ll,样例,particles,joule,energy 来源: https://www.cnblogs.com/rabbit1103/p/16608441.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。