当前位置:网站首页>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
边栏推荐
- Build 2022 上开发者最应关注的七大方向主要技术更新
- What is the at instruction set often used in the development of IOT devices?
- 为了保护自己的数据,他奋斗了一天一夜
- 数据治理:元数据管理实施(第四篇)
- tese_ Time_ 2h
- 【考研高数 自用】高数第一章基础阶段思维导图
- HCM 初学 ( 二 ) - 信息类型
- 移动端常用解决方案
- How to create a progress bar that changes color according to progress
- [QT] QT after addition, subtraction, multiplication and division, two decimal places are reserved
猜你喜欢

Continuous breakthrough and steady progress -- Review and Prospect of cross platform development technology of mobile terminal

基于微信小程序的青少年生理健康知识小助手(免费获取源码+项目介绍+运行介绍+运行截图+论文)

boot+jsp的高校社團管理系統(附源碼下載鏈接)

In depth understanding of condition source code interpretation and analysis of concurrent programming

Simple implementation of database connection pool

从诺奖知“边缘计算”的未来!

Crossing sect · paipan + Siyuan notes = private notebook
![[medical segmentation] u2net](/img/b3/b1d188216310fe1217e360ac56af3b.jpg)
[medical segmentation] u2net

excel高级绘图技巧100讲(一)-用甘特图来展示项目进度情况

JDBC common interview questions
随机推荐
新手在挖财开通证券账户安全吗?
HCM 初学 ( 四 ) - 时间
移动端常用解决方案
mysql 将毫秒数转为时间字符串
为什么用葫芦儿派盘取代U盘?
输入一个表达式(用字符串表示),求这个表达式的值。
Orcle创建用户+角色
[excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc
从诺奖知“边缘计算”的未来!
Data governance: data governance management (Part V)
为了保护自己的数据,他奋斗了一天一夜
Enter an expression (expressed as a string) and find the value of this expression.
MySQL converts milliseconds to time string
2/15 (awk, awk conditions, awk processing design can perform additional tasks, and use awk array +for loop to realize advanced search)
Deeply understand the underlying implementation principle of countdownlatch in concurrent programming
C语言初阶——牛客网精选好题
Send you through the data cloud
[ffmpeg] [reprint] image mosaic: picture in picture with wheat
Unity uses SQLite
Looking for high school student developers with similar interests