JOJ2236:Balance and Poise
来源:互联网 发布:赵泓霖免费网络公开课 编辑:程序博客网 时间:2024/05/21 11:14
传送门:http://acm.jlu.edu.cn/joj/showproblem.php?pid=2236
思路:
n只要能整除3就不断的除3,同时用sum累计除的那些3乘起来多少,这样保证n * sum是原始n,如果n不能整除3了分量中情况,1.余数是1,说明可以从其中拿走一个,所以右盘增加当前sum,n--;如果余数是2,所明需要补足一个,所以左盘增加当前sum,n++。
代码:
#include <iostream>#include <cstdio>using namespace std;int main(){ int n; int left[50], right[50]; while (scanf("%d", &n) != EOF) { int sum = 1, l = 0, r = 0; while (n) { while (n % 3 == 0) n /= 3, sum *= 3; if (n % 3 == 1) right[r++] = sum, n--; else if (n % 3 == 2) left[l++] = sum, n++; } if (l == 0) cout << "0 left, "; else { for (int i = 0; i < l; ++i) cout << left[i] << " "; cout << "left, "; } for (int i = 0; i < r; ++i) cout << right[i] << " "; cout << "right." << endl; } return 0;}
- JOJ2236:Balance and Poise
- 2236: Balance and Poise
- joj2236
- Balance Continuity and Change
- apache + tomcat load balance and cluster
- Vysper cluster, load balance, and LVS
- Balance between code efficiency and code readability
- Balance
- balance
- Balance
- Balance between coverage more function and clear spec.
- Work and Life: 15 Ways to Strike a Balance
- install mongrel for rails and apache http for load balance
- Tomcat load balance and clustering - tomcat负载均衡和集群
- poj1028 Ignatius and the Princess III hdu1709The Balance
- linux irq balance and RT linux(中断线程化)
- Load Balance Tomcat with Nginx and Store Sessions in Redis
- mode manual load-balance and mode lacp-static
- 看伪码写算法 归并算法
- 图片漫画效果(DoG算子和双边滤波)
- FileTracker : error FTK1011解决方法
- SQL的优化
- 在word文档中嵌入另外的word文档
- JOJ2236:Balance and Poise
- C#初识——VS2010中的实用功能总结
- windows下nginx安装、配置与使用
- build/envsetup.sh分析
- 精神疲惫
- 存档: 小图片平铺做背景(斜纹)
- 广义表建树
- c/c++中与时间相关的问题
- 20111123这一年就这样了