1.
能拆分(k>0)就把n二等分,不能拆分就返回n,递归就行了
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int chai(int n,int k){
if(n==1)
return 1;
if(k==0)
return n;
if(n%2==1)
return chai(n/2+1,k-1)+1;
else
return chai(n/2,k-1)+1;
}
int main(){
int n,k;
scanf("%d %d",&n,&k);
int res=chai(n,k);
printf("%d\n",res);
return 0;
}
2.
#include<cstdio>
#include<cstdlib>