码迷,mamicode.com
首页 > 其他好文 > 详细

无限序列

时间:2014-10-03 11:16:34      阅读:243      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!