当前位置:网站首页>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
边栏推荐
- It's not that you have a bad mind, but that you haven't found the right tool
- 4GB大文件,如何实时远程传输和共享?
- 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“
- win10、win11中Elan触摸板滚动方向反转、启动“双指点击打开右键菜单“、“双指滚动“
- [medical segmentation] u2net
- First defined here occurs during QT compilation. Causes and Solutions
- QT waiting box production
- C语言初阶——牛客网精选好题
- 小程序常用组件小结
- Looking for high school student developers with similar interests
猜你喜欢
MySQL converts milliseconds to time string
Mongodb学习篇:安装后的入门第一课
[excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc
Advanced cross platform application development (II): uni app practice
穿越派与贸大合作,为大学生增添效率
2/15 (awk, awk conditions, awk processing design can perform additional tasks, and use awk array +for loop to realize advanced search)
Daily code 300 lines learning notes day 11
Don't put your notes and videos everywhere!
从MLPerf谈起:如何引领AI加速器的下一波浪潮
亲爱的派盘用户,我要向您表白!
随机推荐
芯片,建立在沙粒上的帝国!
Qt编译时,出现 first defined here,原因及解决方法
Basic electrician knowledge 100 questions
Is it safe for a novice to open a securities account?
libpng12.so.0: cannot open shared object file: No such file or directory 亲测有效
Unity project experience summary
轩逸保养手册
数据治理:元数据管理实施(第四篇)
POL8901 LVDS转MIPI DSI 支持旋转图像处理芯片
bat操作ftp上传下载命令
运行时候的导包搜索路径虽然pycharm中标红但不影响程序的执行
Debug details under pycharm
从底层结构开始学习FPGA----RAM IP的定制与测试
Educational administration management system of SSM (free source code)
Mongodb學習篇:安裝後的入門第一課
穿越派与贸大合作,为大学生增添效率
Unity uses SQLite
Web Security (x) what is OAuth 2.0?
Brief description of activation function
It's not that you have a bad mind, but that you haven't found the right tool