当前位置:网站首页>(2022牛客多校四)N-Particle Arts(思维)
(2022牛客多校四)N-Particle Arts(思维)
2022-08-01 04:47:00 【AC__dream】
题目:
样例输入:
5
1 2 3 4 5
样例输出:
54/5
题意:
n个粒子,每个粒子有一个能量ai。两两随机碰撞,假如两个例子的能量分别为a和b,那么碰撞一次两粒子的能量分别变为a&b,a|b。求所有粒子能量稳定后的方差。
我们分析两个粒子碰撞后的结果可以发现,对于a和b的二进制位,假如第i位两者都是1,那么碰撞后形成的两个粒子能量的第i位都是1,如果第i位两者都是0,那么碰撞后形成的两个粒子能量的第i位都是0,如果碰撞前a粒子和b粒子能量第i位一个是1一个是0,那么碰撞后形成的粒子第i位也是一个1一个0,但是1是在或运算后的那个粒子上,那么容易发现,每次碰撞都会使得一个粒子的能量变大(也可能不变),而且碰撞后二进制位上1的个数不变,只是有可能从1个粒子转移到另一个粒子上,由于碰撞了无数次,那么肯定使得二进制上的1尽可能地集中在了少数上,最后的稳定态也就是对于任意的i和j,都有(ai|aj,ai&aj)=(ai,aj)或者 (ai|aj,ai&aj)=(aj,ai) 。 所以我们只需要统计一开始给定的n个数中每一位上1出现的次数即可,最后对n个数进行分配,每次都尽可能把1分配在一个数上,最后求一下期望即可。
需要注意的一点就是由于数比较大,所以可能会爆long long,所以建议直接用__int128计算。
下面是代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
const int N=1e5+10;
int cnt[200];
long long a[N],b[N];
int main()
{
long long n;
cin>>n;
for(int i=1;i<=n;i++)
{
int t;
scanf("%lld",&a[i]);
for(int j=0;j<15;j++)
cnt[j]+=(a[i]>>j&1);
}
__int128 ans=0,ans1=0;
for(int i=1;i<=n;i++)
{
for(int j=0;j<15;j++)
if(cnt[j])
{
b[i]|=(1<<j);
cnt[j]--;
}
ans+=b[i];
ans1+=b[i]*b[i];
}
__int128 anss=ans1*n+ans*ans-2*ans*ans;
__int128 t=__gcd(anss,(__int128)n*n);
long long up = anss/t;
long long down = n*n/t;
printf("%lld/%lld",up,down);
return 0;
}
边栏推荐
- Mysql中的数据类型和运算符
- safari浏览器怎么导入书签
- Input input box cursor automatically jumps to the last bug after the previous input
- 请问shake数据库中为什么读取100个collection 后,直接就退出了,不继续读了呢?
- 请问表格储存中用sql只能查询到主键列,ots sql非主键不支持吗?
- mysql中解决存储过程表名通过变量传递的方法
- 时时刻刻保持敬畏之心
- API Design Notes: The pimpl trick
- 解决ffmpeg使用screen-capture-recorder录屏,有屏幕缩放的情况下录不全的问题
- 【愚公系列】2022年07月 Go教学课程 023-Go容器之列表
猜你喜欢
出现Command ‘vim‘ is available in the following places,vim: command not found等解决方法
Typescript22 - interface inheritance
Flink 1.13 (8) CDC
typescript25 - type assertion
Input input box cursor automatically jumps to the last bug after the previous input
Invalid classes inferred from unique values of `y`. Expected: [0 1 2], got [1 2 3]
MySQL4
leetcode:126. Word Solitaire II
UE4 从鼠标位置射出射线检测
罗技鼠标体验记录
随机推荐
云服务器下载安装mongo数据库并远程连接详细图文版本(全)
Typescript22 - interface inheritance
typescript26 - literal types
Mysql中的数据类型和运算符
25. Have you been asked these three common interview questions?
typescript23-元组
怀念故乡的面条
博客系统(完整版)
Message queue MySQL table for storing message data
IJCAI2022 | Hybrid Probabilistic Reasoning with Algebraic and Logical Constraints
A way to deal with infinite debugger
ModuleNotFoundError: No module named ‘tensorflow.keras‘报错信息的解决方法
高数 | 【重积分】线面积分880例题
干货!如何使用仪表构造SRv6-TE性能测试环境
怀念故乡的月亮
【愚公系列】2022年07月 Go教学课程 023-Go容器之列表
基于ProXmoX VE的虚拟化家庭服务器(篇一)—ProXmoX VE 安装及基础配置
Unknown Bounded Array
【愚公系列】2022年07月 Go教学课程 024-函数
typescript21-接口和类型别名的对比