百练:2的幂次方表示
来源:互联网 发布:搜狗壁纸软件 编辑:程序博客网 时间:2024/06/11 20:07
#include <cstdio>#include <iostream>#include <algorithm>using namespace std;void f(int n){if (n == 1){cout << "2(0)";return;}if (n == 2){cout << "2";return;}int num = 1, cnt = 0;while (num <= n){num *= 2;cnt++;}num /= 2;cnt--;if (num == n)//判断能不能直接用2的整数幂表示n{cout << "2(";f(cnt);cout << ")";}else//否则,输出当前2的幂加上一个东西{if (num == 2)//对2这种特殊情况单独考虑{cout << "2";cout << "+";f(n - num);}else{cout << "2(";f(cnt);cout << ")+";f(n - num);}}}int main(){int x;cin >> x;f(x);cout << endl;return 0;}
0 0
- 百练:2的幂次方表示
- 2的幂次方表示
- 2的幂次方表示
- 2的幂次方表示
- 2的幂次方表示
- 2的幂次方表示
- 2的幂次方表示
- 2的幂次方表示题解
- 2的幂次方表示题解
- 2的幂次方表示题解
- 递归之 2的幂次方表示
- openJudge 2的幂次方表示
- openjudge :2的幂次方表示
- CCF NOI1074 2的幂次方表示
- 2的幂次方表示()
- NOIP1998复赛:2的幂次方表示
- 递归-2的幂次方表示
- Java:2的幂次方表示
- 309. Best Time to Buy and Sell Stock with Cooldown
- tensorflow
- 练习
- [c++基础] 程序设计基本概念
- 2.2解密回文——栈
- 百练:2的幂次方表示
- c/c++编译预处理
- libfreenect2+iai_kinect2+kinect v2+ros indigo
- 第四届蓝桥杯马虎的算式
- Storm学习10---tuple 结构
- hdu 2011 多项式求和
- 【BZOJ2073】【POI2004】PRZ(状压dp)
- 网游通讯传输可变长度的数值和数组
- 2.3纸牌游戏——小猫钓鱼