当前位置:网站首页>“蔚来杯“2022牛客暑期多校训练营4 补题题解(N)
“蔚来杯“2022牛客暑期多校训练营4 补题题解(N)
2022-08-03 00:38:00 【QingQingDE23】
“蔚来杯“2022牛客暑期多校训练营4
觉得有帮助的点个赞! [比赛地址](https://ac.nowcoder.com/acm/contest/33189) [参考的大佬题解](https://zhuanlan.zhihu.com/p/548121328)
N Particle Arts
比赛是想出思路了,但是竟然莫名其妙过不去,可能是因为1e5n的n三次方爆了,但是long long明明可以存下这么多,我不理解
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define db double
const int N = 1e5 + 10;
int n;
int a[N];
int cnt[20]; //记录第i位有几个1,从右往左排n~1
int get_wei(int x){
int res = 0;
while(x){
res ++ ;
x >>= 1;
}
return res;
}
int get_er(int x, int y){
//x这个数有y位二进制数
int res = 0;
for(int i = 1; i <= y; i ++ ){
if(x & 1){
res ++ ;
cnt[i] ++ ;
}
x >>= 1;
}
return res;
}
int tui(int iu){
//填充1
int res = 0;
for(int i = iu; i >= 1; i -- ){
if(cnt[i]){
res ++ ;
cnt[i] -- ;
}
res <<= 1;
}
res >>= 1;
return res;
}
int gcd(int a, int b){
if(b) return gcd(b, a % b);
else return a;
}
int li; //记录1的个数
int iu; //最高位有几位
int sum; //计算数值和
int ans1, ans2;
int sut;
signed main()
{
cin>>n;
for(int i = 0; i < n; i ++ ){
scanf("%lld", &a[i]);
sum += a[i];
int r = get_wei(a[i]);
iu = max(iu, r); //记录最高位数
li += get_er(a[i], r); //累加1的个数
}
//sum已记录
for(int i = 0; i < n; i ++ ){
//填充n个数
int t = tui(iu);
ans1 += t * t;
sut += sum * t;
}
ans1 *= n;
ans1 += sum * sum;
ans1 -= 2 * sut;
ans2 = n * n;
int ou = gcd(ans1, ans2);
if(ou > 1){
ans1 /= ou;
ans2 /= ou;
}
//最小公倍数*最大公约数=a*b
//最小公倍数=ans1*n/最大公约数
if(ans1 == 0) cout<<"0/1"<<endl;
else cout<<ans1<<"/"<<ans2<<endl;
return 0;
}
边栏推荐
猜你喜欢
随机推荐
7-Redis工具类
flutter空安全问题,平时用到的数据一定要注意
【SQL】—数据库操作、表操作
SAP 电商云 Spartacus UI 的持续集成 - Continous integration
并查集总结
236. 二叉树的最近公共祖先
麒麟信安邀您抢先看 | openEuler 志高远,开源汇智创未来-开放原子全球开源峰会欧拉分论坛最详细议程出炉
7.31
全栈---JSONP
如何修复 SAP UI5 aggregation with cardinality 0..1 相关的错误消息
async-await
NVM和NRM
智能合约安全-可重入攻击(SW107-Reentrancy)
嵌入式开发:嵌入式基础——’ ’和” ”的区别
.NET深入解析LINQ框架(四:IQueryable、IQueryProvider接口详解)
Oracle 暴跌,倒下了!
UVM中SVA使用指南
吴恩达深度学习deeplearning.ai——第一门课:神经网络与深度学习——第一节:深度学习概论
软件测试从业多年,自认为技术不错,裸辞:一晃 ,失业3个月了~
UPC2022暑期个人训练赛第23场(Credit Card Payment)