标签:style blog color io os for sp div c
描述
1101001000100001000001.......
求第Ai位的数是什么
Ai<=2000000
因为可以推出所有1位置的序号
就可以用一个数组给存起来
又因序号是递增的
所以就可以二分来查找
1 # include<cstdio> 2 # include<cstring> 3 # include<iostream> 4 # include<algorithm> 5 using namespace std; 6 typedef unsigned long long LL; 7 const int maxn=50000; 8 const int INF=900000000; 9 LL f[maxn]; 10 int two_find(LL l,LL r,LL x){ 11 while(l<r){ 12 LL mid=(l+r)>>1; 13 if(f[mid]==x)return 1; 14 else if(f[mid]>x)r=mid; 15 else l=mid+1; 16 } 17 return 0; 18 } 19 int main(){ 20 ios::sync_with_stdio(false); 21 LL cur=0,tb=1,num=1,n,x; 22 while(f[cur++]<=INF){ 23 f[cur]=num; 24 num=num+tb; 25 tb++; 26 } 27 cin>>n; 28 for(int i=1;i<=n;i++){ 29 cin>>x; 30 if(two_find(1,cur,x))printf("1\n"); 31 else printf("0\n"); 32 } 33 return 0; 34 }
标签:style blog color io os for sp div c
原文地址:http://www.cnblogs.com/zoniony/p/4004734.html