首页 > 其他 > 详细

51Nod 1087 1 10 100 1000

时间:2017-07-26 12:09:51      阅读:261      评论:0      收藏:0      [点我收藏+]
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 #include <iostream>
 2 #include <algorithm>
 3 #include <stdio.h>
 4 #include <cstring>
 5 using namespace std;
 6 #define ll long long
 7 int main()
 8 {
 9     int n;
10     cin>>n;
11     while(n--){
12         int a,s=0;
13         cin>>a;
14         for(int i=1; ;i++){
15             if(i==1) s+=i;
16             else s+=i-1;
17             if(s>a){
18                 cout<<0<<endl;
19                 break;
20             }
21             else if(s==a){
22                 cout<<1<<endl;
23                 break;
24             }
25         }
26     }
27     return 0;
28 }

 

51Nod 1087 1 10 100 1000

原文:http://www.cnblogs.com/shixinzei/p/7238752.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!