acdream 20140730 D题

今天见识到了“数学上来先打表”............

#include<iostream>
using namespace std;
#include<iomanip>
#define LL long long
/*
int lowbit(int n)
{
    int t,cnt = 1;
    t = n % 2;
    if(t == 1) return 1;
    while(t == 0)
    {
        cnt *= 2;
        n /= 2;
        t = n % 2;
    }
    return cnt;
}
LL d(int n)
{
    LL ans = 0;
    for(int i = 1; i <= n; i++)
        ans += lowbit(i);
    return ans;
}
*/
//经过打表,得f(x) = 2 * f( x / 2) + n / 2 + ( n & 1 )
LL d(int n)
{
    if(n == 1)return 1;
    LL ans = 2 * d(n / 2) + n / 2 + (n & 1);
    return ans;
}
int main()
{
    int n;
    while(cin>>n)
    {
        cout<<d(n)<<endl;
    }
    return 0;
}

acdream 20140730 D题,布布扣,bubuko.com

时间: 2024-10-11 22:29:34

acdream 20140730 D题的相关文章

Acdream 1111:LSS(水题,字符串处理)

LSS Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Others) SubmitStatistic Next Problem Problem Description Time flies, four years passed, colleage is over. When I am about to leave, a xuemei ask me an ACM  problem, but

一道超级坑爹的水题(ACdream oj 无耻的出题人)

 A - 无耻的出题人 Time Limit: 2000/1000 MS (Java/Others)      Memory Limit: 65536/32768 KB (Java/Others) Submit Status Problem Description 听到X神要参加比赛,只会Fibnacci数的出题人被吓得哭晕在厕所.为了防止X神AK(ALL KILL)比赛题目,无耻的出题人只好在题面上做些手脚(加密).其中一道题的题目描述如下: hjxh dwh v vxxpde,mmo i

acdream B - 郭式树 (水题 卡cin,cout, 卡LL)

题目 输入正好是long long的最大, 但是答案超long long 所以用unsigned, 不能用cin cout否则一定超时: 不能用abs(), abs 只用于整数. unsigned   int   0-4294967295   int   2147483648-2147483647 unsigned long 0-4294967295long   2147483648-2147483647long long的最大值:9223372036854775807long long的最小值

ACdream 1213 Matrix Multiplication【水题 、 找规律】

Matrix Multiplication Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) 链接:http://acdream.info/problem?pid=1213 Problem Description Let us consider undirected graph G = {V; E} which has N vertices and M edges. Incidence

ACdream oj C - 神奇的%系列一 (水题系列--略坑)

 C - 神奇的%系列一 Time Limit: 6000/3000 MS (Java/Others)      Memory Limit: 65536/32768 KB (Java/Others) Submit Status Problem Description 在计算机的世界里,%不是百分比,而是除法取余哟! 比如: 4 % 2 = 0 5 % 3 = 2 给你 2<=N<=100000 个数,a[1],a[2]...a[i]...a[n]. 其中:1<=a[i]<=10

虐我半下午的水题(ACdream无耻的出题人)

对于这道题我只想说坑爹.绝对的坑爹. 还有这样出题的..... 无耻的出题人 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 KB (Java/Others) SubmitStatistic Next Problem Problem Description 听到X神要参加比赛,只会Fibnacci数的出题人被吓得哭晕在厕所.为了防止X神AK(ALL KILL)比赛题目,无耻的出题人只好在题面上做些手脚(加密).其中

一道字符串水题LSS(ACdream)

一道水题但是我错了好惨 罚时罚到最后一名 Problem Description Time flies, four years passed, colleage is over. When I am about to leave, a xuemei ask me an ACM  problem, but I can't solve it, I am 功力尽失.  Please help me so that I won't lose face in front of xuemei! Give y

acdream 1738 世风日下的哗啦啦族I

原题链接:http://acdream.info/problem?pid=1738 树套树裸题,如下: 1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #define lc root<<1 7 #define rc root<<1|1 8 using std::so

ACdream 1099 瑶瑶的第K大

瑶瑶的第K大 Time Limit: 10000/5000MS (Java/Others)Memory Limit: 512000/256000KB (Java/Others) SubmitStatisticNext Problem Problem Description 一天,萌萌的妹子--瑶瑶(tsyao)很无聊,就来找你玩.可是你们都不知道玩什么...尴尬了一阵子,机智的瑶瑶就提议:"这样吧,你说N个整数xi,然后在随意说一个数字k,我能够快速地说出这些数字里面第 k 大的数字."