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

#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;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-17
  • 2021-10-22
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-19
  • 2022-12-23
  • 2021-12-30
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案