51nod 1087 1 10 100 1000【二分】
来源:互联网 发布:科瑞明软件 怎么样 编辑:程序博客网 时间:2024/06/06 00:53
1087 1 10 100 1000
题目来源: Ural 1209
基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题
收藏
关注
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示例
3123
Output示例
110
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespace std;const int maxn = 1e5 + 10;int pre[maxn];int main(){ int t; int n; cin >> t; pre[1] = 1; for(int i = 2; i < maxn; i++) pre[i] = pre[i-1] + i; while(t--) { cin >> n; int l = 1, r = maxn; int mid,ans; while(l <= r) { mid = (l + r) >> 1; if(pre[mid] <= n){ ans = mid; l = mid + 1; } else r = mid - 1; } //cout << ans; if(pre[ans] == n || n - pre[ans] > 1) cout << "0" << endl; else cout << "1" << endl; } return 0;}
0 0
- 二分51nod-1087 1 10 100 1000
- 51nod 1087 1 10 100 1000【二分】
- 51nod-1087 . 1 10 100 1000
- 51NOD 1087 1 10 100 1000
- 51nod 1087 1 10 100 1000
- 51nod 1087 1 10 100 1000
- 51nod 1087 1 10 100 1000
- 51nod-【1087 1 10 100 1000】
- 51nod 1087 1 10 100 1000
- 51nod 1087 1 10 100 1000
- 51nod 1087 1 10 100 1000
- 【51Nod】1087 1 10 100 1000
- 51nod 1087 1 10 100 1000
- 51Nod 1087 1 10 100 1000
- 51nod 1267【二分】
- 51Nod - 1065 二分
- 51nod 1087 1 10 100 1000(数学问题)
- 51 nod一级算法题:1087 1 10 100 1000
- Sequence Number -acm
- bzoj 1079 [SCOI2008]着色方案
- ldd命令
- Spring容器
- C#中字符串的一些方法
- 51nod 1087 1 10 100 1000【二分】
- javascript对象及内置对象属性和方法
- 扫雷
- Android中的ACTION_SEND与ShareCompat
- Perl-创建自己的包来共享函数
- 配置vim的C++开发环境
- #pragma once与#define #ifndef ...#endif的区别
- 有序数组统计各个数字出现的次数
- 使用计算着色器(Compute Shader)模拟粒子效果【OpenGL】【GLSL】