当前位置:网站首页>Code shoe set - mt3114 · interesting balance - explain it with examples
Code shoe set - mt3114 · interesting balance - explain it with examples
2022-07-01 05:45:00 【Tisfy】
Portal
Interesting balance
The time limit :1 second
Space restriction :64M
Title Description
Small brother likes balance very much , One day, brother Xiaoma received a seesaw from a friend , When the weight of both sides of the seesaw is the same, it reaches balance . Just right , He has some weights 2 0 , 2 1 ⋯ , 2 ∞ 2^0,2^1\cdots,2^{\infty} 20,21⋯,2∞, There is only one weight of each kind , Brother Xiaoma hopes to put some weights on both sides , So that the absolute value of the weight difference between the two sides is x x x, Weights must be placed on both sides , You can't let go of weights , Can you do it for me , Give your method .
Input description
Enter an integer x ( 1 ≤ x < 2 30 ) x(1\le x< 2^{30}) x(1≤x<230)
Output description
Output four lines
The first line represents the number of French yards on the left
The second row lists the weight of the weight that represents the left weight
A number in the third line represents the number of weights on the right
The fourth row lists the weight of the weight placed by the weight on the right
Each line of numbers is separated by a space
remarks :
Any method to satisfy the meaning of the question is legal
Example 1
Input
6
Output
1
2
1
8
Topic analysis
In fact, we can count x x x In binary terms .
For example, in the example 6 = 11 0 ( 2 ) 6=110_{(2)} 6=110(2)
Then we calculate x x x How many bits are there in the binary of
Examples 6 6 6 Binary system 110 110 110 Yes 3 3 3 position
Then we put a weight of... On one side of the balance 2 position Count 2^{ digit } 2 position Count The weight of
Examples 6 6 6 The weight placed on one side of is 2 3 = 8 2^{3}=8 23=8 The weight of
Then we calculate the weight of the weight that needs to be placed on the other side ( Write it down as r e m a i n remain remain) r e m a i n = 2 position Count − x remain=2^{ digit }-x remain=2 position Count −x
Examples 6 6 6 Put the weight on the other side of the r e m a i n remain remain by 8 − 6 = 2 8-6=2 8−6=2
Finally, put r e m a i n remain remain Written in binary form , The first i i i Position as 1 1 1 If so, put a weight of 2 i 2^i 2i The weight of ( From 0 0 0 From the beginning )
Examples 6 6 6 The other side 2 = 1 0 ( 2 ) 2=10_{(2)} 2=10(2), The first 0 0 0 Is it 0 0 0, The first 1 1 1 Is it 1 1 1, So put a weight of 2 1 = 2 2^1=2 21=2 The weight of .
Here we are , Problem solving .
AC Code
#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;
int main() {
int n;
cin >> n;
int k = 1;
while (k <= n) {
k *= 2;
}
int remain = k - n;
cout << 1 << endl;
cout << k << endl;
vector<int> right;
int k2 = 1;
while (k2 < k) {
if (k2 & remain) {
right.push_back(k2);
}
k2 *= 2;
}
cout << right.size() << endl;
for (int i = 0; i < right.size(); i++) {
cout << right[i] << ' ';
}
puts("");
return 0;
}
Update the weekly competition solution of elite class in advance every week , Focus , Neverlost
Originality is not easy. , Reprint please attach Link to the original text Oh ~
Tisfy:https://letmefly.blog.csdn.net/article/details/125545873
边栏推荐
- Orcle创建用户+角色
- Multi table operation - foreign key cascade operation
- Crossing pie · pie pan + Mountain duck = local data management
- 穿越派·派盘 + 思源笔记 = 私人笔记本
- Mongodb學習篇:安裝後的入門第一課
- 【考研高数 自用】高数第一章基础阶段思维导图
- 如何添加葫芦儿派盘
- HDU - 1069 Monkey and Banana(DP+LIS)
- 论文学习记录随笔 多标签之LSML
- Vscode function annotation / file header annotation shortcut
猜你喜欢
SSM的教务管理系统(免费源码获取)
![[excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc](/img/c8/e3e31ad9ef214d97228cb501dd752f.jpg)
[excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc

OpenGL ES: (5) OpenGL的基本概念、OpenGL ES 在屏幕产生图片的过程、OpenGL管线(pipeline)

【考研高数 自用】高数第一章基础阶段思维导图

穿越派与贸大合作,为大学生增添效率

多表操作-外键级联操作

这才是大学生必备软件 | 知识管理
![Fiber Bragg grating (FBG) notes [1]: waveguide structure and Bragg wavelength derivation](/img/83/97c0c6e23cbb7b4c2b630c217c5206.jpg)
Fiber Bragg grating (FBG) notes [1]: waveguide structure and Bragg wavelength derivation

【知识点总结】卡方分布,t分布,F分布

Typeorm framework
随机推荐
In win10 and win11, the scroll direction of Elan touch panel is reversed, and "double finger click to open the right-click menu" and "double finger scroll" are started“
excel高级绘图技巧100讲(一)-用甘特图来展示项目进度情况
扩展点系列之SmartInstantiationAwareBeanPostProcessor确定执行哪一个构造方法 - 第432篇
MySQL数据迁移遇到的一些错误
[excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc
穿越派·派盘 + 思源笔记 = 私人笔记本
为了保护自己的数据,他奋斗了一天一夜
HCM 初学 ( 一 ) - 简介
【问题思考总结】为什么寄存器清零是在用户态进行的?
OpenGL ES: (1) OpenGL ES的由来 (转)
亲爱的派盘用户,我要向您表白!
Leetcode top 100 questions 1 Sum of two numbers
In depth understanding of condition source code interpretation and analysis of concurrent programming
多表操作-外键级联操作
Typeorm framework
Ucosiii --- engineering transplantation
Ssgssrcsr differences
Continuous breakthrough and steady progress -- Review and Prospect of cross platform development technology of mobile terminal
【笔记】电商订单数据分析实战
Boot + jsp University Community Management System (with source Download Link)