1. 程式人生 > >2018-軟工機試-E-熱河路(TLE只拿了90分,待思考)

2018-軟工機試-E-熱河路(TLE只拿了90分,待思考)

抽象 ace body 單擊 i++ 理發店 strong sam 表示

單點時限: 2.0 sec

內存限制: 256 MB

沒有人在熱河路談戀愛,
總有人在天亮時傷感
如果年輕時你沒來過熱河路,
那你現在的生活是不是很幸福
——李誌《熱河》

奔跑。跌倒。奔跑。

熱河路有一家開了好多年的理發店,不管剪什麽樣的發型,你只要付五塊錢。現在我們來到了熱河路。

我們可以將其抽象成一個如下的序列:

110100100010000100000……

請你找出這個無窮序列中指定位置上的數字。

輸入格式

第一行一個正整數 n (1n1500000 ),表示詢問次數。

接下來的 n 行,每行一個正整數

ai (1ai109 ),ai 表示在序列中的位置。

輸出格式

輸出 n 行,每行為一個 01 ,表示該序列第 ai 位上的數字。

樣例

Input
4
3
14
7
6
Output
0
0
1
0

 1 #include<stdio.h>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<iostream>
 6 #include<algorithm>
 7
using namespace std; 8 9 10 11 int main() 12 { 13 int n,a; 14 scanf("%d",&n); 15 for(int i=1;i<=n;i++) 16 { 17 scanf("%d",&a); 18 if(a==1) 19 printf("1\n"); 20 else 21 { 22 int j=1; 23 while
(a>j) 24 { 25 a-=j; 26 j++; 27 } 28 if(a==1) 29 printf("1\n"); 30 else 31 printf("0\n"); 32 } 33 } 34 return 0; 35 }

2018-軟工機試-E-熱河路(TLE只拿了90分,待思考)