当前位置:网站首页>(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;
}
边栏推荐
- Typescript22 - interface inheritance
- Software Testing Weekly (Issue 82): In fact, all those who are entangled in making choices already have the answer in their hearts, and consultation is just to get the choice that they prefer.
- 开源许可证 GPL、BSD、MIT、Mozilla、Apache和LGPL的区别
- Message Queuing Message Storage Design (Architecture Camp Module 8 Jobs)
- 怀念故乡的面条
- Excel record of integer programming optimization model to solve the problem
- Logitech Mouse Experience Record
- What is dynamic programming and what is the knapsack problem
- The difference between scheduleWithFixedDelay and scheduleAtFixedRate
- 在互联网时代,有诸多「互联网+」模式的诞生
猜你喜欢
随机推荐
The method of solving stored procedure table name passing through variable in mysql
怀念故乡的月亮
基于STM32设计的UNO卡牌游戏(双人、多人对战)
在沈自所的半年总结
typescript28-枚举类型的值以及数据枚举
Excel record of integer programming optimization model to solve the problem
Interview Blitz 69: Is TCP Reliable?Why?
The Flow Of Percona Toolkit pt-table-checksum
Software Testing Weekly (Issue 82): In fact, all those who are entangled in making choices already have the answer in their hearts, and consultation is just to get the choice that they prefer.
7月编程排行榜来啦!这次有何新变化?
Step by step hand tearing carousel Figure 3 (nanny level tutorial)
Character encoding and floating point calculation precision loss problem
typescript23-元组
Optional parameters typescript19 - object
UE4 制作遇到的问题
safari浏览器怎么导入书签
状态压缩dp
智芯传感输液泵压力传感器 为精准智能控制注入科技“强心剂”
typescript22-接口继承
这里有110+公开的专业数据集









