P1010 幂次方

这么难得题,居然普及-?做了好久

#include <bits/stdc++.h>
using namespace std;
int fact[21];
void solve(int n) {
if(n == 0) {cout << 0; return;}
if(n == 2) {cout << 2; return;}
while(n) {
int x = floor(log(n)/log(2));
if(x!=1){cout << 2 << '(';
solve(x);} else {cout << 2;
}
n-=fact[x];
if(x!=1)cout << ')' ;
if(n) cout << '+';
}
}
int main() {
int ans = 1;
for(int i = 0; i<=20; i++) {
fact[i] = ans;
ans *= 2;
}
int n;
cin >> n;
solve(n);
return 0;
}
上一篇:在eclipse中安装配置WebDriver


下一篇:Arrays.sort的粗略讲解