0
点赞
收藏
分享

微信扫一扫

【51nod - 1087】 1 10 100 1000(找规律推公式,水,map)

耶也夜 2022-06-15 阅读 89

题干:

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。

Sample Input


3 1 2 3

Sample Output


1 1 0

解题报告:

    用了map,刚开始直接冲一下50W的数组发现1e8多,然后开了70W发现成了1e7.。。于是发现可能是开大了然后试了试5W发现就1e9多了。

AC代码:

#include<bits/stdc++.h>

using namespace std;
int a[50000 + 5];
map<int , int> mp;
int main()
{
int top = -1;
a[0] = 1;
mp[a[0] ] = 1;
for(int i = 1 ;i<=50000 && a[i]<=(int)1e9; i++) {
a[i] = a[i-1]+i;
mp[a[i] ] =1;
}
int t,n;
// cout<<a[50000];
cin>>t;
while(t--) {
scanf("%d",&n);
printf("%d\n",mp[n]);
}
return 0 ;
}

这题数据出水了啊,不用map也能过?因为最大数据是1e8.。。看代码:

#include<bits/stdc++.h>

using namespace std;
int a[50000 + 5];
map<int , int> mp;
int main()
{
int top = -1;
a[0] = 1;
mp[a[0] ] = 1;
for(int i = 1 ;i<=50000 && a[i]<=(int)1e9; i++) {
a[i] = a[i-1]+i;
mp[a[i] ] =1;
}
int t,n;
// cout<<a[50000];
cin>>t;
while(t--) {
scanf("%d",&n);
if(n > 100001010) printf("hahaha\n");
printf("%d\n",mp[n]);
}
return 0 ;
}

 


举报

相关推荐

0 条评论