当前位置:网站首页>“蔚来杯“2022牛客暑期多校训练营4 N
“蔚来杯“2022牛客暑期多校训练营4 N
2022-08-04 12:23:00 【eyuhaobanga】
将答案的公式结合起来化简可得
,
这样不会爆long long,只需要处理出最终趋于稳定的数组的形式,可知a+b=a&b+a|b,操作无数次,总和是不变的
AC代码:
#include <bits/stdc++.h> #define rep(i,a,n) for(int i=a;i<n;i++) using namespace std; using LL = long long; LL gcd(LL x, LL y) { return y == 0 ? x : gcd(y, x % y); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); LL n; cin >> n; vector<LL> a(n + 1); LL maxx = 0; LL sum = 0; vector<LL> pos(16, 0); for (int i = 1; i <= n; i ++ ) { cin >> a[i]; sum += a[i]; } if (sum == 0) { cout << "0/1\n"; return 0; } for (int i = 1; i <= n; i ++ ) { for (int j = 0; j <= 15; j ++ ) { if(1 << j & a[i]) { pos[j]++; } } } vector<LL> x; for (int i = 1; i <= n; i ++ ) { LL t = 0; for (int j = 15; j >= 0; j -- ) { if(pos[j]) { t += (1 << j); pos[j]--; } } if(t) x.push_back(t); else break; } int len = x.size(); LL ans = -sum * sum; for (int i = 0; i < n; i++) { if (i < len) ans += n * x[i] * x[i]; else { break; } } LL c = gcd(ans, n * n); cout << ans / c << "/" << n * n / c << '\n'; return 0; }
边栏推荐
- 七夕疯狂搞钱的年轻人,一周赚14万
- ShanDong Multi-University Training #4 A、B、C、G
- 广告电商系统开发之订单处理
- Focusing on data sources, data quality and model performance to build a credit profile of small and micro enterprises
- 如何做好企业数字化转型?这10份靠谱案例收藏了(附下载)
- Hit the interview!The latest interview booklet of Ali Jin, nine silver and ten is stable!
- 论文翻译:2022_Time-Frequency Attention for Monaural Speech Enhancement
- MySQL索引原理以及SQL优化
- 手搓一个“七夕限定”,用3D Engine 5分钟实现烟花绽放效果
- String是引用类型
猜你喜欢
随机推荐
推荐一款优秀的通用管理后台
动手学深度学习_LeNet
拥有一台服务器,程序猿装X的开始
Valentine's Day Romantic 3D Photo Wall [with source code]
来 TDengine 开发者大会,洞悉数据技术发展的未来趋势
How to develop small program plug-ins to achieve profitability?
break与continue超详解!!!
【PHP实现微信公众平台开发—基础篇】第2章 微信公众账号及申请流程详解
免费翻译软件哪个好用
如何做好企业数字化转型?这10份靠谱案例收藏了(附下载)
Transferring Rich Feature Hierarchies for Robust
企业应当实施的5个云安全管理策略
Cool and efficient data visualization big screen, it's really not that difficult to do!丨Geek Planet
飞书更新招聘功能 候选人可选择面试时间
matlab串口读写
Tarjan 求有向图的强连通分量
企业应当实施的5个云安全管理策略
云原生Devops 的实现方法
《独行月球》猛药,治不了开心麻花内耗
Redis (1) installation and configuration