当前位置:网站首页>[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 .
边栏推荐
- The coming wave of Web3
- Principle of event delegation
- From meeting a big guy to becoming a big guy, shengteng AI developer creation day brings infinite possibilities to developers
- Establishment of SSH Framework (Part 2)
- native关键字的作用
- 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
- OracleData安装问题
- Moonbeam集成Coin98,给予用户在多链道路上的更多选择
- UI自动化测试框架搭建 —— 编写一个APP自动化
- Multithreading and high concurrency six: source code analysis of thread pool
猜你喜欢

Tiktok actual battle ~ take off the blogger

Digital promising, easy to reach, Huawei accelerates the layout of the commercial market with "five pole" star products

Uncover the mystery of SSL and learn how to protect data with SSL

Pinda general permission system (day 5~day 6)

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

抖音實戰~關注博主

Why are cloud vendors targeting this KPI?

Necessary skills for test and development: actual combat of security test vulnerability shooting range

Severe tire damage: the first rock band in the world to broadcast live on the Internet

Google Earth Engine(GEE)——全球洪水数据库 v1 (2000-2018年)
随机推荐
玩转双指针
一文详解|增长那些事儿
Uncover the mystery of SSL and learn how to protect data with SSL
To quickly download JDK, in addition to the official Oracle download, is there a download address for the latest version available in China
Analyse complète annuelle du marché chinois de l'audio en 2022
xml&nbsp; File read / write
Matlab exercises -- routine operation of matrix
Source code of live video system, countdown display, countdown of commodity spike
A queue of two stacks
Go语言学习教程(十四)
leetcode:714. The best time to buy and sell stocks includes handling fee [DP dual status]
Huawei's 9-year experience as a software testing director
Bitlock recovery occurs in win 10, and the blue screen error code is 0x1600007e
Recommended by Alibaba P8, Fiddler packet capturing tool (I)
Role of native keyword
The growth summer challenge is coming | learn and create two major tracks, and start the tutor registration!
Principle of event delegation
测试/开发程序员真的是青春饭吗?世界是公平的,咱们都凭实力说话......
CDC全量抽取mysql数据时,怎么才能加快ChunkSplitter呢?
Pinda general permission system (day 5~day 6)