首页 > 其他分享 >"蔚来杯"2022牛客暑期多校训练营4 N-Particle Arts

"蔚来杯"2022牛客暑期多校训练营4 N-Particle Arts

时间:2022-08-20 19:11:21浏览次数:73  
标签: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
From: https://www.cnblogs.com/rabbit1103/p/16608441.html

相关文章

  • "蔚来杯"2022牛客暑期多校训练营3 C-Concatenation
    问题描述NIOwasthekingoftheOINKingdom.HehadNNNchildrenandwantedtoteachthemhowtocount.IntheOINKingdom,pentalisusedincounting,sohis......
  • "蔚来杯"2022牛客暑期多校训练营2 G-Link with Monotonic Subsequence
    问题描述First,let'sreviewsomedefinitions.Feelfreetoskipthispartifyouarefamiliarwiththem.Asequence aaaisanincreasing(decreasing)subsequ......
  • "蔚来杯"2022牛客暑期多校训练营1 G-Lexicographical Maximum
    问题描述EibwenisanewbieinPython.Youmightknowthatwhenyouinputanumberinthecommandline,yourPythonprogramwillreceiveastringcontainingth......
  • "蔚来杯"2022牛客暑期多校训练营1 - D Mocha and Railgun
    问题描述ThereisacandystorenearMocha'sschool.It'ssaidthatthestorekeeper,Dagashiya,cancasttherailgunspell.TobethemostpowerfulMahouShouj......
  • "蔚来杯"2022牛客暑期多校训练营4
    A.TaskComputing给定\(n\)个任务,每个任务有两个权值\(w_i,p_i\),从中按任意顺序选出\(m\)个任务\((a_1,a_2,...,a_m)\),收益为\(\sum\limits_{i=1}^mw_{a_i}\prod\limits_{......
  • echarts 数据的各种格式
    数据集数据集(dataset)是专门用来管理数据的组件。虽然每个系列都可以在series.data中设置数据,但是从ECharts4支持数据集开始,更推荐使用数据集来管理数据。因为这样......
  • ECharts 中的样式简介
    ECharts中的样式简介本文主要是大略概述,用哪些方法,可以在ApacheEChartsTM中设置样式,改变图形元素或者文字的颜色、明暗、大小等。为了让表述更通俗易懂,我们在这里用......
  • echarts 图表容器及大小
    图表容器及大小在快速上手中,我们介绍了初始化ECharts的接口echarts.init。API文档中详细介绍了参数的具体含义,建议理解后再阅读本文。下面,我们就常见的几种使用场景,......
  • 学习:python pyecharts数据可视化
    pyecharts数据可视化pyecharts是一个用于生成Echarts图标的类库Echarts是百度开源的一个数据可视化的Js库用Echarts生成的图可视化效果非常棒 新版v1和老版本......
  • 在vue中使用echarts
    1.引入echarts先通过npm安装echartsnpmrunecharts--save2.在main.js中import*asechartsfrom'echarts';Vue.prototype.$echarts=echarts3.在.vue文件中(包括......