当前位置:网站首页>“蔚来杯“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;
}
边栏推荐
猜你喜欢

【深度学习】基于tensorflow的小型物体识别训练(数据集:CIFAR-10)

Vite教程 安装

TensorFlow学习记录(一):基本介绍

稳压电源: 电路图及类型

吴恩达深度学习deeplearning.ai——第一门课:神经网络与深度学习——第一节:深度学习概论

NLP commonly used Backbone model cheat sheet (1)

和睦家私有化后换帅:新风天域吴启楠任CEO 李碧菁靠边站

8 个常用的 Wireshark 使用技巧,一看就会

智能合约安全-可重入攻击(SW107-Reentrancy)

如何快速对接淘宝开放平台API接口(淘宝店铺订单明文接口,淘宝店铺商品上传接口,淘宝店铺订单交易接口)
随机推荐
华为防火墙双机热备技术:HRP、VGMP、VRRP,三大技术值得一学!
C# 异步编程(async和await)
如何修复 SAP UI5 aggregation with cardinality 0..1 相关的错误消息
JSP第一篇 -----JSP九大内置对象(隐式对象)和四大域对象
北路智控上市首日破发:公司市值59亿 募资15.6亿
全栈---CORS
暴力递归到动态规划 08(小马走象棋)
关于地图GIS开发事项的一次实践整理(上)
Carefully organize 16 MySQL usage specifications to reduce problems by 80% and recommend sharing with the team
.NET深入解析LINQ框架(四:IQueryable、IQueryProvider接口详解)
esp32和ros2基础篇草稿-micro-ros-
FreeRTOS任务管理
有奖提问|《新程序员》专访“Apache之父”Brian Behlendorf
SAP ABAP OData 服务如何支持修改(Update)操作试读版
可编程逻辑控制器(PLC) : 基础、类型和应用
ASP.NET网络版进销存管理系统源码【源码免费分享】
记一次sql优化Using temporary; Using filesort
PAT甲级 1051 Pop Sequence
【深度学习】基于tensorflow的小型物体识别训练(数据集:CIFAR-10)
30岁测试开发年薪不足80万,还要被面试官diss混得太差?