当前位置:网站首页>“蔚来杯“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;
}
边栏推荐
- npm运行项目dependencies were not found: core-js/modules/es6.array.fill
- 科捷智能冲刺科创板:年营收12.8亿 顺丰与日日顺是股东
- 图文详细解决IDEA使用Debug模式启动项目一直转圈圈跑起不来(亲测可以)
- js垃圾回收机制
- Auto.js 特殊定位控件方法 不能在ui线程执行阻塞操作,请使用setTimeout代替
- 8 个常用的 Wireshark 使用技巧,一看就会
- 一套开源的可快速搭建自己的物联网/智能家居系统源码
- DB2数据库-获取表结构异常:[jcc][t4][1065][12306][4.26.14]CharConvertionException ERRORCODE=-4220,SQLSTATE=null
- 「PHP基础知识」隐式数据类型
- 从一文中了解SSRF的各种绕过姿势及攻击思路
猜你喜欢
PAT甲级 1051 Pop Sequence
从 npm 切换到 pnpm,真香!
电压传感器: 工作原理、类型及电路图
【遥控器开发基础教程5】疯壳·开源编队无人机-SPI(2.4G 双机通信)
线上交流丨稀疏神经网络:实践和理论(青源Talk第23期 汪张扬)
matlab常微分方程在传染病建模中的应用
【深度学习】基于tensorflow的小型物体识别训练(数据集:CIFAR-10)
2022 开放原子全球开源峰会 | 麒麟信安携手openEuler助力开源产业繁荣发展
npm运行项目dependencies were not found: core-js/modules/es6.array.fill
2022年8月2日——使用idea搭建servlet+jsp项目
随机推荐
OpenWRT设置ipv6网络
作业8.2 线程同步互斥机制——互斥锁
Qt在选择MSVC 编译器的时候,无法识别出M_PI的问题处理
php一维数组合并
有奖提问|《新程序员》专访“Apache之父”Brian Behlendorf
科捷智能冲刺科创板:年营收12.8亿 顺丰与日日顺是股东
爆款视频怎么做?这里或许有答案
线上交流丨稀疏神经网络:实践和理论(青源Talk第23期 汪张扬)
一个接口并发问题的模拟与复现
236. 二叉树的最近公共祖先
XSS攻击
【遥控器开发基础教程4】疯壳·开源编队无人机-SPI(OLED)
鲲鹏devkit开发套件
alibaba数据同步组件canal的实践整理
并发模型和I/O模型介绍
js显示隐藏手机号
letcode 第20题-有效的括号
淘宝商品销量接口/淘宝商品销量监控接口/商品累计销量接口代码对接分享
php提示Array to string conversion
【MySQL —— 数据库约束】