当前位置:网站首页>2021 CCPC Harbin I. power and zero (binary + thinking)
2021 CCPC Harbin I. power and zero (binary + thinking)
2022-07-04 21:21:00 【GHOSTANDBREAD】
In view of :I. Power and Zero( Binary system , thinking )_Looy_cai The blog of -CSDN Blog
Ideas :
Convert a string of decimal numbers into binary , Then add the digits , At this time, it may not be increasing from high to low , So we need to convert from high to low . Until from high to low, there is no decreasing state . At this time, the last one , That is, the one with the largest number , That's the answer. .
Be careful :
When converting a string of numbers to binary , The binary length of each number may be different , So record the maximum length as the length of the binary array .
When switching from high to low , There is no guarantee that the state of non decreasing can be achieved by switching once , because bit[1] and bit[2] After the transformation ,bit[2] and bit[3] After conversion ,bit[2] It's getting smaller ,bit[1] And than bit[2] big , Therefore, it is necessary to keep cycling until the binary array reaches the state of no decrement from high to low .
Code :
#include<iostream>
#include<cstring>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int t, n;
int bit[50];
int main() {
scanf("%d", &t);
while(t --) {
scanf("%d", &n);
int x;
int len = -1;
memset(bit, 0, sizeof bit);
for(int i = 0; i < n; i ++) {
scanf("%d", &x);
int ind = 0;
while(x) {
bit[++ ind] += x % 2;
x /= 2;
}
len = max(len, ind);
}
bool ok = true;
while(ok) {
ok = false;
for(int i = len; i >= 2; i --) {
if(bit[i] > bit[i - 1]) {
ok = true;
int avg = (bit[i] * 2 + bit[i - 1]) / 3;
bit[i - 1] += (bit[i] - avg) * 2;
bit[i] = avg;
}
}
}
printf("%d\n", bit[1]);
}
return 0;
}
边栏推荐
- 为什么说不变模式可以提高性能
- MySQL - database query - use of aggregate function, aggregate query, grouping query
- 【服务器数据恢复】某品牌服务器存储raid5数据恢复案例
- Render function and virtual DOM
- redis布隆过滤器
- 【微服务|SCG】Predicate的使用
- 网件r7000梅林系统虚拟内存创建失败,提示USB磁盘读写速度不满足要求解决办法,有需要创建虚拟内存吗??
- Roast B station charges, is it because it has no money?
- In the face of the same complex test task, why can the elder sort out the solution quickly? Ali's ten-year test engineers showed their skills
- 杰理之AD 系列 MIDI 功能说明【篇】
猜你喜欢
Routing configuration and connectivity test of Huawei simulator ENSP
heatmap.js图片热点热力图插件
Explication détaillée du mécanisme de distribution des événements d'entrée multimodes
杰理之AD 系列 MIDI 功能说明【篇】
MySQL - database query - use of aggregate function, aggregate query, grouping query
MySQL --- 数据库查询 - 聚合函数的使用、聚合查询、分组查询
maya灯建模
WGCNA分析基本教程总结
Billions of citizens' information has been leaked! Is there any "rescue" for data security on the public cloud?
Golang中UTF编码和字符集
随机推荐
[Shenbo introduction] VI How to contact your favorite doctoral tutor
记一次重复造轮子(Obsidian 插件设置说明汉化)
Test case (TC)
多模输入事件分发机制详解
基于OpenCV haarcascades的对象检测
y56.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(二九)
Hwinfo hardware detection tool v7.26 green version
LeetCode+ 81 - 85 单调栈专题
Difference between ApplicationContext and beanfactory (MS)
Huawei ENSP simulator configures ACL access control list
heatmap.js图片热点热力图插件
ApplicationContext 与 BeanFactory 区别(MS)
shp数据制作3DTiles白膜
PS竖排英文和数字文字怎么改变方向(变竖直显示)
杰理之AD 系列 MIDI 功能说明【篇】
偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
RFID仓库管理系统解决方案有哪些功能模块
Roast B station charges, is it because it has no money?
Jmeter 之压测入门
Procurement in software development