您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: