URAL 1209 110100100010000……

URAL 1209 110100100010000……

/*
此题纠结了n久
感觉自己的方法应该是最高效的解法了
但每次提交都超时
后来发现原来是上界弄错了
无语。。。 
*/
#define LOCAL
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
#ifdef LOCAL
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
#endif
    int n,first=1;double k;unsigned long t;
    cin>>n;
    while(n--){
    cin>>k;
    t=(long)sqrt(2*k);//就是这得上界弄错了 
    while((t*(t+1))>(2*(k-1))) t-=1;
    if((t*(t+1))==(2*(k-1)))
    {if(first){cout<<1;first=0;}                
    else{cout<<" 1";}}   
    else{if(first){cout<<0;first=0;}                
    else{cout<<" 0";}}}
    cout<<endl;
    return 0;
}

发表回复