其他分享
首页 > 其他分享> > SYCOJ#111、吉祥物

SYCOJ#111、吉祥物

作者:互联网

题目—吉祥物 (shiyancang.cn)

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n,x;
 4 int pos(int n)
 5 {
 6     int s=1,j=1;
 7     while(s<n)
 8     {
 9         s+=j++;
10      } 
11     return s;
12 }
13 int main()
14 {
15     scanf("%d",&n);
16     while(n--)
17     {
18         scanf("%d",&x);
19         if(x==pos(x)) cout<<"1"<<endl;
20         else cout<<"0"<<endl;
21      } 
22     return 0;
23 }

题目中的排列是有规律的,很明显1是递增数列的位置,那么只需要预处理出来对应a的位置,如果访问的等于a 的位置,那么就是的了,如果不是那么就不是.
很多东西可以预处理,会方便很多。

标签:那么,题目,int,位置,预处理,吉祥物,111,SYCOJ
来源: https://www.cnblogs.com/Astronaut0142/p/14853964.html