首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ZOJ 3498 Javabeans

ZOJ 3498 Javabeans

作者头像
ShenduCC
发布2018-04-26 16:52:24
4970
发布2018-04-26 16:52:24
举报
文章被收录于专栏:算法修养算法修养

Javabeans Time 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

4 1 2 3 4 Sample Output

1 2 2 3

找规律

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
using namespace std;

int main(){
    int n;
    int flag;
    long long int a[40];
    a[0]=1;
    for(int i=1;i<32;i++){
        a[i]=a[i-1]*2;
    }
    scanf("%d",&n);
    while(n--){
        long long int t;
        scanf("%lld",&t);
        for(int i=1;i<32;i++){
            if(t>=a[i-1]&&t<a[i]){
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-04-22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档