ZOJ 3498 Javabeans(找规律)
2017-02-10 15:45
274 查看
JavabeansTime Limit: 2 Seconds Memory Limit: 65536 KB
Javabeans are delicious. Javaman likes to eat javabeans very much.
Javaman has n boxes of javabeans. There are exactly i javabeans in the i-th box (i = 1, 2, 3,...n). Everyday Javaman chooses an integer x. He also chooses several boxes where the numbers of javabeans are all at least x. Then he eats x javabeans in each box he has just chosen. Javaman wants to eat all the javabeans up as soon as possible. So how many days it costs for him to eat all the javabeans?
Input
There are multiple test cases. The first line of input is an integer T ≈ 100 indicating the number of test cases.
Each test case is a line of a positive integer 0 < n < 231.
Output
For each test case output the result in a single line.
Sample Input
Sample Output
题解:找规律
盒子数目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17……
吃完要求的天数:
1 2 2 3 3 3 3 4 4 4 4 4 4 4 4 5 5……
Author: CAO, Peng
Contest: The 8th Zhejiang Provincial Collegiate Programming Contest
Javabeans are delicious. Javaman likes to eat javabeans very much.
Javaman has n boxes of javabeans. There are exactly i javabeans in the i-th box (i = 1, 2, 3,...n). Everyday Javaman chooses an integer x. He also chooses several boxes where the numbers of javabeans are all at least x. Then he eats x javabeans in each box he has just chosen. Javaman wants to eat all the javabeans up as soon as possible. So how many days it costs for him to eat all the javabeans?
Input
There are multiple test cases. The first line of input is an integer T ≈ 100 indicating the number of test cases.
Each test case is a line of a positive integer 0 < n < 231.
Output
For each test case output the result in a single line.
Sample Input
4 1 2 3 4
Sample Output
1 2 2 3
题解:找规律
盒子数目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17……
吃完要求的天数:
1 2 2 3 3 3 3 4 4 4 4 4 4 4 4 5 5……
Author: CAO, Peng
Contest: The 8th Zhejiang Provincial Collegiate Programming Contest
#include <iostream> #include<cstdio> using namespace std; int t; long long n; long long ans[33]; int main() { ans[0]=1; for(int i=1;i<=31;i++) ans[i]=ans[i-1]*2; //之前爆int了,要用long long /*for(int i=1;i<=31;i++) printf("%d:%lld\n",i,ans[i]);*/ while(~scanf("%d",&t)) { for(int i=1;i<=t;i++) { scanf("%lld",&n); for(int j=1;j<=31;j++) { if (ans[j]<n) continue; if (ans[j]==n) printf("%d\n",j+1); else printf("%d\n",j); break; } } } return 0; }
相关文章推荐
- ZOJ 3498 Javabeans【规律】
- ZOJ 3498 Javabeans
- ZOJ Problem Set - 3498||Javabeans
- ZOJ 3498 Javabeans
- ZOJ 3498 Javabeans
- zoj 3498 Javabeans
- zoj 3498 javabeans
- ZOJ 3498 Javabeans
- ZOJ - 3498 Javabeans
- ZOJ 3498 Javabeans
- ZOJ 3498 Javabeans【水】
- zoj 3498 Javabeans
- ZOJ 3498 Javabeans (二分)
- ZOJ 3498 Javabeans
- ZOJ 3498 Javabeans(数学)
- ZOJ 3498 L - Javabeans
- ZOJ 2316 Matrix Multiplication(找规律)(矩阵和它的转置矩阵之积)
- zoj 3622 Magic Number (找规律+打表)
- ZOJ 3829 Known Notation --贪心+找规律
- ZOJ 3785 11th省赛 J What day is that day?【打表找规律】