[HNOI2006] Guiguzi's purse, Luogu's improved experience, the magical solution

text

      Question 4: [HNOI2006] Guiguzi's purse

      From this question, we can think of the nature of dichotomy, a number must be added to the power of 2.

      Then it is easy to know that when a number is even, divide it into two equal parts to recurse.

      When a number is odd, we pass down the smaller number after dividing by 2.

      This can make the number of decomposition smaller.

      Then, because the decomposed numbers are from large to small, it is added to the queue when returning to make the resulting number smaller.

#include<cstdio>
#include<cstdlib>
#include<cstring>

int n;
int on[10010];
int t=0;

void dfs(int x){
	int p=(x+1)/2;
	if(x-p>1)dfs(x-p);
	else on [++ t] = xp;
	op[++t]=p;
}

int main(){
	scanf("%d",&n);
	dfs(n);
	printf("%d\n",t);
	for(int i=1;i<=t;i++)
		printf("%d ",op[i]);
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325978187&siteId=291194637