51 nod 1087 1 10 100 1000 (set)

来源:互联网 发布:iphone7和8的区别知乎 编辑:程序博客网 时间:2024/06/16 03:46

http://www.51nod.com/onlineJudge/submitDetail.html#!judgeId=347416

思路:规律题。

第(i*(i+1))/2+1项是1 ,其它是0,预处理求出所有为1的项,用set记录,然后直接查询。

#include<iostream>#include<cstring>#include<stdio.h>#include<set>#define maxn 45000using namespace std;int main(){  int t,n;  set<long long>s;  for(long long x=0;x<=maxn;x++)    s.insert((x*(x+1))/2);  scanf("%d",&t);  while(t--)  {      scanf("%d",&n);      n--;   if(s.count(n)==1)    printf("1\n");   else    printf("0\n");  }}
原创粉丝点击