zoukankan      html  css  js  c++  java
  • hdu 5587 Array 二分

    Array

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)



    Problem Description
    Vicky is a magician who loves math. She has great power in copying and creating.
    One day she gets an array {1}。 After that, every day she copies all the numbers in the arrays she has, and puts them into the tail of the array, with a signle '0' to separat.
    Vicky wants to make difference. So every number which is made today (include the 0) will be plused by one.
    Vicky wonders after 100 days, what is the sum of the first M numbers.
     
    Input
    There are multiple test cases.
    First line contains a single integer T, means the number of test cases.(1T2103)
    Next T line contains, each line contains one interger M. (1M1016)
     
    Output
    For each test case,output the answer in a line.
     
    Sample Input
    3 1 3 5
     
    Sample Output
    1 4 7
     
    Source
    题目链接:点击传送
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    #define eps 1e-14
    #define bug(x)  cout<<"bug"<<x<<endl;
    const int N=1e5+30010,M=1e6+10,inf=2147483647;
    const ll INF=1e18+10,mod=2147493647;
    set<ll>s;
    set<ll>::iterator it;
    ll dfs(ll n)
    {
        //cout<<n<<endl;
        if(n==0) return 0;
        it=s.find(n);
        if(it!=s.end())
           return 2*dfs(n/2)+n-n/2;
        it=s.upper_bound(n);
        it--;
        ll x=n-(*it);
        ll z=(*it);
        return dfs(z)+dfs(x-1)+n-z;
    }
    int main()
    {
        for(int i=0;i<55;i++)
            s.insert((1LL<<i)-1);
        int T;
        scanf("%d",&T);
        while(T--)
        {
            ll n;
            scanf("%lld",&n);
            ll ans=dfs(n);
            printf("%lld
    ",ans);
        }
        return 0;
    }
     
  • 相关阅读:
    页面控制多角度看Model1与Model2
    类型抽象Haxe3新增特性:抽象类型 Abstract Types
    hadoop配置Hadoop 2.0分布式环境搭建安装配置
    PostThreadMessage的应用
    禁用安全模式(2k,2k3,xp)
    如何使用内存池监视器 (Poolmon.exe) 解决内核模式内存泄漏
    WideCharToMultiByte,MultiByteToWideChar
    禁止stMgr.exe
    GetCurrentUserSid
    注册表修改大全
  • 原文地址:https://www.cnblogs.com/jhz033/p/6627709.html
Copyright © 2011-2022 走看看