zoukankan      html  css  js  c++  java
  • (bc #45) A

    Dylans loves numbers

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
    Total Submission(s): 569    Accepted Submission(s): 320


    Problem Description
    Who is Dylans?You can find his ID in UOJ and Codeforces.
    His another ID is s1451900 in BestCoder.

    And now today's problems are all about him.

    Dylans is given a number N.
    He wants to find out how many groups of "1" in its Binary representation.

    If there are some "0"(at least one)that are between two "1",
    then we call these two "1" are not in a group,otherwise they are in a group.
     
    Input
    In the first line there is a number T.

    T is the test number.

    In the next T lines there is a number N.

    0N1018,T1000
     
    Output
    For each test case,output an answer.
     
    Sample Input
    1 5
     
    Sample Output
    2
     
    Source
     
     
     
    快要炸了..
    tle成狗
     
    因为是tle,看了下自己没有写cin cout,估计就是算法的问题...
    我是先存了二进制的每一位到数组,然后扫一遍...
    嗯,这都tle...
    那我不存不扫,直接记录当前二进制位和之前二进制位..
    logn的复杂度总可以了吧啊?
    还TLE..........
    嗯,其实已经发现 n是小于等于1e18的,没开long long 
    但是一位没开long long 会是wa...就没理...
    之后实在黔驴技穷,改了下,竟然过了...
    然后想明白了.
    因为存二进制的时候有一个while
    没开long long 的话就炸了,不知道读进去的是什么,while就出不来,于是就tle了.T T
    果然太年轻.
    /*************************************************************************
        > File Name: code/bc/#45/1001.cpp
        > Author: 111qqz
        > Email: rkz2013@126.com 
        > Created Time: 2015年07月29日 星期三 13时25分01秒
     ************************************************************************/
    
    #include<iostream>
    #include<iomanip>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #include<cstring>
    #include<string>
    #include<map>
    #include<set>
    #include<queue>
    #include<vector>
    #include<stack>
    #define y0 abc111qqz
    #define y1 hust111qqz
    #define yn hez111qqz
    #define j1 cute111qqz
    #define tm crazy111qqz
    #define lr dying111qqz
    using namespace std;
    #define REP(i, n) for (int i=0;i<int(n);++i)  
    typedef long long LL;
    typedef unsigned long long ULL;
    const int inf = 0x7fffffff;
    const int N=1E3+5;
    int a[N];
    LL n,nn;
    int main()
    {
        int T;
        cin>>T;
        while (T--)
        {
        scanf("%lld",&n);
        nn = n ;
        int k = 0;
        while (nn)
        {
            k++;
            a[k]=nn&1;
            nn = nn >>1;
        }
        int ans = 0;
    //    for ( int i = 1 ; i <= k ; i++ )
    //        cout<<a[i]<<endl;
        for ( int i = 1 ; i <= k ; i++ )
        {
            if (a[i]==1&&a[i-1]==0)
            ans++;
        }
        printf("%d
    ",ans);
        }
        return 0;
    }
     
  • 相关阅读:
    FileWriter简单用法并记录日志
    jquery 替换元素函数
    jquery ajax应用
    jquery 操作对象和集合
    jquery 管理包装元素集合
    jQuery 过滤选择器
    @Html.Action()
    ASP.NET MVC之Html.RenderAction
    MVC5中路由新特性
    MVC5学习整理
  • 原文地址:https://www.cnblogs.com/111qqz/p/4685837.html
Copyright © 2011-2022 走看看