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
41234Sample Output
1223
Author: CAO, PengContest: The 8th Zhejiang PRovincial Collegiate Programming Contest題意:有n個盒子。第i個盒子有i個javabean,每天可以選擇一個x,然后把盒子里有大于等于x個javabeans里吃掉x個,問最少需要幾天才能吃完。
解題思路:n個盒子,每天吃(n+1)/2個,最多的盒子剩下n/2個
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <algorithm>#include <cmath>#include <queue>#include <vector>#include <set>#include <stack>#include <map>#include <climits>using namespace std;#define LL long longconst int INF=0x3f3f3f3f;int main(){ int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); int sum=0; while(n) { n/=2; sum++; } printf("%d/n",sum); } return 0;}
新聞熱點
疑難解答