csuoj-1727-The Fake Coin
2016-04-24 18:31
429 查看
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
3 2 3 4
Sample Output
1 1 2
n个硬币,一个硬币假的比较重,问你最少称几次能把他称出来。
然后分三堆啊
好像初中奥数吧
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #define MAXN 10010 using 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; }
相关文章推荐
- QT基础(二)----鼠标、键盘事件处理机制、信息拦截机制
- 02-一次请求的开始与结束
- layoutSubview的方法总结
- 20145215《Java程序设计》第8周学习总结
- CString由Unicode转为utf8格式
- 第6讲 SQL语言概述
- 使用 jquery.validate.messages_cn.js 插件实现表单自动验证,出现中文乱码
- 文章标题
- python基础练习(四)—— 读取文件内容
- (SDL)(01)SDL Introduction
- csuoj-1723-想打架吗?算我一个!所有人,都过来!
- 01-从SAPI接口开始
- Struts学习总结
- 关于 Android 进程保活,你所需要知道的一切
- 北京林业大学“计蒜客”杯程序设计竞赛 网络赛
- php面试题及答案收藏(转)
- C++ URLEncode编码
- csuoj-1726-你经历过绝望吗?两次!
- html
- 链接贴子为自己以后方便查阅