zoukankan      html  css  js  c++  java
  • 51nod 1087 1 10 100 1000

    1,10,100,1000...组成序列1101001000...,求这个序列的第N位是0还是1。
     
    Input
    第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)
    第2 - T + 1行:每行1个数N。(1 <= N <= 10^9)
    Output
    共T行,如果该位是0,输出0,如果该位是1,输出1。
    Input示例
    3
    1
    2
    3
    Output示例
    1
    1
    0
    预处理记录下每个1的位置 尽量多记录也别太多 容易TLE
    我是用Map存的 没爆空间 。
    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <map>
    
    using namespace std;
    
    typedef long long LL;
    void read(LL &x)
    {
        x=0;LL f=1;
        char ch=getchar();
        while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+(int)ch-48;ch=getchar();}
        x=x*f; 
    }
    map<LL,bool>q;
    LL T,i,n;
    int main()
    {
        q[1]=1; 
        LL sum=1;
        for(i=1;i<=100501;++i)
        {
            sum+=i;
            q[sum]=1;
        }
        read(T);
        while(T--)
        {
            read(n);
            if(q[n])
            cout<<"1"<<endl;
            else cout<<"0"<<endl;
        }
        return 0;
    }
    
    
    
     
    我们都在命运之湖上荡舟划桨,波浪起伏着而我们无法逃脱孤航。但是假使我们迷失了方向,波浪将指引我们穿越另一天的曙光。
  • 相关阅读:
    算法系列:杂项
    算法系列:
    Algo: Dynamic programming
    Algo:
    算法系列:XXX
    算法系列:量子计算与量子通信
    算法系列:Reservoir Sampling
    算法系列:CSAPP 推荐
    算法系列:
    算法系列:geometry
  • 原文地址:https://www.cnblogs.com/ruojisun/p/6381293.html
Copyright © 2011-2022 走看看