Kolakoski

题目链接

题意

给出一个规则构造数列。

思路

按题意暴力模拟即可。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[33;1m" << #x << "->" ; err(x);} while (0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x){for (auto v: a) cout << v << ' '; err(x...);}
template<typename T, typename... A>
void err(T a, A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
#define inf 1ll << 50
const int maxn=1e7+10;
int arr[maxn];
queue<int> q;
void init(){
int cnt=0;
arr[++cnt]=1;
q.push(2);
int cur=1;
int flag=1;
while(!q.empty() && cnt<maxn-2){
int tmp=q.front();
q.pop();
cnt++;
arr[cnt]=((arr[cnt-1]-1)^1)+1;
q.push(arr[cnt]);
if(flag){
q.pop(); flag--;
}
if(tmp==2){
cnt++;
arr[cnt]=arr[cnt-1];
q.push(arr[cnt]);
}
}
}
int main(){
init();
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
printf("%d\n",arr[n]);
}
}
0%