当前位置:网站首页>[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 .
边栏推荐
- Find an SQL that can judge the data in the table and only fill in the SQL that is not overwritten
- 10:00面试,10:02就出来了 ,问的实在是太...
- 求一个能判断表中数据,只填充不覆盖的sql
- [matlab traffic light identification] traffic light identification [including GUI source code 1908]
- 快速下载JDK,除了官方Oracle下载,还有国内可以有最新版本的下载地址吗
- Genicam gentl standard ver1.5 (2)
- [applet] solution document using font awesome Font Icon (picture and text)
- mysql导入文本文件时的pager
- The SQL of filincdc always reports this error when there are multiple tables. How can I solve it
- Aspnetcoreratelimit rate limit interface access limit current limit control
猜你喜欢

leetcode:714. 买卖股票的最佳时机含手续费【dp双状态】

Oracledata installation problems

One article explains in detail | those things about growth

Ppt production tips

恭喜我自己,公众号粉丝破万

Genicam gentl standard ver1.5 (2)

Web3来临时的风口浪尖

【Matlab BP回归预测】GA优化BP回归预测(含优化前的对比)【含源码 1901期】

How do I get the STW (pause) time of a GC (garbage collector)?
![leetcode:714. The best time to buy and sell stocks includes handling fee [DP dual status]](/img/e4/5ec39aced223512b162020d05eb313.png)
leetcode:714. The best time to buy and sell stocks includes handling fee [DP dual status]
随机推荐
UI自動化測試框架搭建 —— 編寫一個APP自動化
Mise en place d'un cadre d'essai d'automatisation de l'interface utilisateur - - rédaction d'une application d'automatisation
Go language learning tutorial (14)
Oracledata installation problems
多线程实现 重写run(),怎么注入使用mapper文件操作数据库
玩转双指针
Uncover the mystery of SSL and learn how to protect data with SSL
leetcode:714. The best time to buy and sell stocks includes handling fee [DP dual status]
Is it true that qiniu business school gives away securities accounts? Is it safe to open an account
短视频平台开发,点击链接、图片自动跳转到新的页面
Password encryption MD5 and salt treatment
如何遍历collections.OrderedDict,服了又忘记items
What are the password requirements for waiting insurance 2.0? What are the legal bases?
Secouer le son et se battre ~ prêter attention au blogueur
Annual comprehensive analysis of China's audio market in 2022
Multithreading and high concurrency V: detailed explanation of wait queue, executor and thread pool (key)
mysql导入文本文件时的pager
Moonbeam integrates coin98, giving users more choices on the multi chain road
native关键字的作用
Necessary skills for test and development: actual combat of security test vulnerability shooting range