当前位置:网站首页>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
边栏推荐
- Don't put your notes and videos everywhere!
- Build 2022 上开发者最应关注的七大方向主要技术更新
- Continuous breakthrough and steady progress -- Review and Prospect of cross platform development technology of mobile terminal
- 从MLPerf谈起:如何引领AI加速器的下一波浪潮
- 加密狗资料搜集
- 2/15 (awk, awk conditions, awk processing design can perform additional tasks, and use awk array +for loop to realize advanced search)
- Dear pie users, I want to confess to you!
- What is the at instruction set often used in the development of IOT devices?
- RecycleView的一些使用
- 导数的左右极限和左右导数的辨析
猜你喜欢

MySQL数据迁移遇到的一些错误

Daily code 300 lines learning notes day 11

MySQL converts milliseconds to time string

Huluer app help

Educational administration management system (free source code)

论文学习记录随笔 多标签之GLOCAL

如何添加葫芦儿派盘

激活函数简述

Through cooperation with the University of international trade, we can increase efficiency for college students

Send you through the data cloud
随机推荐
MySQL数据迁移遇到的一些错误
CentOS 7使用yum安装PHP7.0
Boot + jsp University Community Management System (with source Download Link)
Dear pie users, I want to confess to you!
Enter an expression (expressed as a string) and find the value of this expression.
bat操作ftp上传下载命令
【QT】qt加减乘除之后,保留小数点后两位
JDBC常见面试题
新手在挖财开通证券账户安全吗?
Flowable source code comment (XXXIX) task listener
scope 数据导出mat
Crossing pie · pie pan + Mountain duck = local data management
芯片,建立在沙粒上的帝国!
boot+jsp的高校社团管理系统(附源码下载链接)
Typeorm framework
数据治理:元数据管理实施(第四篇)
Continue to learn MySQL
【笔记】电商订单数据分析实战
穿越派·派盘 + 思源笔记 = 私人笔记本
rust猜数字游戏