当前位置:网站首页>[csp-j2020] excellent splitting
[csp-j2020] excellent splitting
2022-06-28 04:46:00 【Pandaoxi】
[CSP-J2020] Excellent split
Title Description
Generally speaking , A positive integer can be split into the sum of several positive integers .
for example , 1 = 1 1=1 1=1, 10 = 1 + 2 + 3 + 4 10=1+2+3+4 10=1+2+3+4 etc. . For positive integers n n n A specific split of , Let's call it alpha “ first-class ”, If and only if under this split , n n n It's broken down into a number of Different Of 2 2 2 Of Positive integer The next power . Be careful , a number x x x Can be expressed as 2 2 2 The positive integer power of , If and only if x x x Can pass a positive integer 2 2 2 Multiply together to get .
for example , 10 = 8 + 2 = 2 3 + 2 1 10=8+2=2^3+2^1 10=8+2=23+21 Is an excellent split . however , 7 = 4 + 2 + 1 = 2 2 + 2 1 + 2 0 7=4+2+1=2^2+2^1+2^0 7=4+2+1=22+21+20 It's not an excellent split , because 1 1 1 No 2 2 2 The positive integer power of .
Now? , Given a positive integer n n n, You need to judge all the splits of this number , Is there a good split . If exist , Please give us the specific split plan .
Input format
There is only one line of input , An integer n n n, Represents the number to be judged .
Output format
If all the splits of this number , There are excellent splits . that , You need to output every number in this split from large to small , Separate two adjacent numbers with a space . Can prove that , After specifying the order of splitting numbers , The splitting scheme is unique .
If there is no good split , Output -1.
Examples #1
The sample input #1
6
Sample output #1
4 2
Examples #2
The sample input #2
7
Sample output #2
-1
Tips
Examples 1 explain
6 = 4 + 2 = 2 2 + 2 1 6=4+2=2^2+2^1 6=4+2=22+21 Is an excellent split . Be careful , 6 = 2 + 2 + 2 6=2+2+2 6=2+2+2 Not a good split , Because it's split into 3 3 3 The number is not satisfied, and each number is different from each other .
Data scale and agreement
- about 20 % 20\% 20% The data of , n ≤ 10 n \le 10 n≤10.
- For another 20 % 20\% 20% The data of , Guarantee n n n It's odd .
- For another 20 % 20\% 20% The data of , Guarantee n n n by 2 2 2 The positive integer power of .
- about 80 % 80\% 80% The data of , n ≤ 1024 n \le 1024 n≤1024.
- about 100 % 100\% 100% The data of , 1 ≤ n ≤ 10 7 1 \le n \le {10}^7 1≤n≤107.
//Author:PanDaoxi
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n,a[27]={
1};
cin>>n;
if(n%2==1||n==2){
cout<<"-1"<<endl;
}
else{
for(int i=1;i<=26;i++) a[i]=a[i-1]*2;
for(int i=26;i>=1;i--){
if(n>=a[i]){
n-=a[i];
cout<<a[i]<<" ";
}
}
}
return 0;
}

done .
边栏推荐
- Multi project design and development · introduction to class library project
- Matlab exercises -- basic data processing
- Tiktok actual battle ~ take off the blogger
- Games104 operation 2-colorgrading
- Multithreading and high concurrency II: detailed introduction to volatile and CAS
- Aspnetcoreratelimit rate limit interface access limit current limit control
- Are test / development programmers really young? The world is fair. We all speak by strength
- Ppt production tips
- Role of native keyword
- Necessary skills for test and development: actual combat of security test vulnerability shooting range
猜你喜欢

June 27, 2022: give a 01 string with a length of N. now please find two intervals so that the number of 1 and the number of 0 in the two intervals are equal. The two intervals can intersect, but not c

成长一夏 挑战赛来袭 | 学习、创作两大赛道,开启导师报名啦!

first. Net core MVC project
![[Matlab bp regression prediction] GA Optimized BP regression prediction (including comparison before optimization) [including source code 1901]](/img/73/1e4c605991189acc674d85618cf0ef.png)
[Matlab bp regression prediction] GA Optimized BP regression prediction (including comparison before optimization) [including source code 1901]

Pinda general permission system (day 5~day 6)

How do I get the STW (pause) time of a GC (garbage collector)?

论文详读:IMPROVING CONVOLUTIONAL MODELS FOR HANDWRITTEN TEXT RECOGNITION

The coming wave of Web3

玩转双指针

UI automation test framework construction - write an app automation
随机推荐
【Matlab BP回归预测】GA优化BP回归预测(含优化前的对比)【含源码 1901期】
Why are cloud vendors targeting this KPI?
Pager when importing text files from MySQL
Go语言学习教程(十四)
TACo:一种关于文字识别的数据增强技术
恭喜我自己,公众号粉丝破万
CUPTI error: CUPTI could not be loaded or symbol could not be found.
Audio and video technology development weekly
leetcode:714. 买卖股票的最佳时机含手续费【dp双状态】
多线程实现 重写run(),怎么注入使用mapper文件操作数据库
Multithreading and high concurrency IV: varhandle, strong weak virtual reference and ThreadLocal
Find an SQL that can judge the data in the table and only fill in the SQL that is not overwritten
Google Earth engine (GEE) - global flood database V1 (2000-2018)
Introversion, lying flat and midlife crisis
代码理解:IMPROVING CONVOLUTIONAL MODELS FOR HANDWRITTEN TEXT RECOGNITION
Introduction to multi project development, basic design class library project use
Flinkcdc collects Oracle, and the Oracle database is CDB's
阿里P8倾情推荐,Fiddler抓包工具实战篇(一)
Difference between curdate() and now()
Database garbled