csuoj-1727-The Fake Coin
来源:互联网 发布:逆波兰式算法 编辑:程序博客网 时间:2024/06/05 04:09
Description
There are n coins,one of them is fake.The fake coin is heavier than a genuine one.If you have a balance,how many times at least you need to use it to find the fake coin?
Input
The first line contains an integer T (T<=100), means there are T test cases.
For each test case, there is only one line with an integer n (1 <= n <= 10000). The num of coins.
Output
For each test case, output the least times you need.
Sample Input
3234
Sample Output
112
n个硬币,一个硬币假的比较重,问你最少称几次能把他称出来。
然后分三堆啊
好像初中奥数吧
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#define MAXN 10010using namespace std; int main(){ int a[MAXN]; int tot = 1; a[0] = 1; for (int i = 1; a[i-1] < MAXN; i++) { a[i] = a[i-1] * 3; tot++; } int t; scanf("%d", &t); while (t-- ) { int n; scanf("%d", &n); for (int i = 0; i <= tot; i++) { if (n <= a[i]) { printf("%d\n", i); break; } } } return 0;}
0 0
- csuoj-1727-The Fake Coin
- CSU 1727: The Fake Coin
- HOJ 2519 Fake coin
- Hoj 2519 Fake coin
- CSUOJ
- CSUOJ
- The Coin Change Problem
- the difference of real and fake fingerprint
- 5 Drease-and-Conquer Fake-Coin Problem(减治法求假币问题)
- POJ 3260 The Fewest Coin
- [Hackerrank] The Coin Change Problem
- CSUOJ 1862 The Same Game 模拟消消乐
- .Coin
- Coin
- Hackerrank - Coin on the Table 题解
- hackerrank The Coin Change Problem(dp)
- Fake Glasses
- fake email
- LoaderManager使用详解(二)---了解LoaderManager
- Android 主题和样式
- 01-从SAPI接口开始
- 文章标题
- hibernate实现Tree
- csuoj-1727-The Fake Coin
- CString由Unicode转为utf8格式
- linux 下 lamp 编译安装 20160424 szx
- 02-一次请求的开始与结束
- layoutSubview的方法总结
- IE插件开发注意事项
- javascript高级程序设计(4-5)章笔记
- 03-一次请求生命周期
- v4l2 编程接口(二) — driver