51nod 1087 1 10 100 1000
2018-03-12 19:11
232 查看
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1087
思路:先预处理出1所在的下标,然后二分查找
AC代码:#include<bits/stdc++.h>
using namespace std;
const int MAXN = 70005;
int a[MAXN], k = 1;
void preProcess() {
a[0] = 1;
while (a[k - 1] + k <= 1000000000) {
a[k] = a[k - 1] + k;
k++;
}
}
int main() {
preProcess();
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int *p = lower_bound(a, a + k, n);
if (*p == n) {
printf("1\n");
}
else {
printf("0\n");
}
}
return 0;
}
思路:先预处理出1所在的下标,然后二分查找
AC代码:#include<bits/stdc++.h>
using namespace std;
const int MAXN = 70005;
int a[MAXN], k = 1;
void preProcess() {
a[0] = 1;
while (a[k - 1] + k <= 1000000000) {
a[k] = a[k - 1] + k;
k++;
}
}
int main() {
preProcess();
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int *p = lower_bound(a, a + k, n);
if (*p == n) {
printf("1\n");
}
else {
printf("0\n");
}
}
return 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] 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【二分】