Kolakoski

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)

Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1…….
This sequence consists of 1 and 2,
and its first term equals 1.
Besides, if you see adjacent and equal terms as one group, you will get 1,22,11,2,1,22,1,22,11,2,11,22,1…….
Count number of terms in every group, you will get the sequence itself. Now, the sequence can be uniquely determined. Please tell HazelFan its nth
element.
 

Input
The first line contains a positive integer T(1≤T≤5),
denoting the number of test cases.

For each test case:

A single line contains a positive integer n(1≤n≤107).
 

Output
For each test case:

A single line contains a nonnegative integer, denoting the answer.
 

Sample Input

2
1
2
 

Sample Output

1
2
 

Statistic | Submit | Clarifications | Back

#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const int maxn = 1e7 + 100;
int table[maxn] = { 0,1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1 };
int table1[maxn] = { 0,1 };
long long int ti = 2;
int tem = 1;
void init() {
for (int i = 2; ti < maxn-50; ++i) {
tem = tem % 2 + 1;
if (table[i] == 2) {
table1[ti] = tem;
table[ti++] = tem;
table1[ti] = tem;
table[ti++] = tem;
}
else {
table1[ti] = tem;
table[ti++] = tem;
}
}
}
int main()
{
init();
int t;
cin >> t;
long long int n;
while (t--)
{
cin >> n;
cout << table1[n] << endl; }
return 0;
}

2017杭电多校第七场1011Kolakoski的更多相关文章

  1. 2017杭电多校第七场1005Euler theorem

    Euler theorem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) ...

  2. 2017杭电多校第六场1008 Kirinriki

    传送门 Kirinriki Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  3. 2017杭电多校第五场11Rikka with Competition

    Rikka with Competition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  4. 2017杭电多校第五场Rikka with Subset

    Rikka with Subset Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  5. 杭电多校第七场 1010 Sequence(除法分块+矩阵快速幂)

    Sequence Problem Description Let us define a sequence as below f1=A f2=B fn=C*fn-2+D*fn-1+[p/n] Your ...

  6. 杭电多校第七场-J-Sequence

    题目描述 Let us define a sequence as belowYour job is simple, for each task, you should output Fn module ...

  7. 2017杭电多校第六场1011Classes

    传送门 Classes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tota ...

  8. 2017杭电多校第六场03Inversion

    传送门 Inversion Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  9. hdu61272017杭电多校第七场1008Hard challenge

    Hard challenge Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) ...

随机推荐

  1. intent使用Serializable传递对象

    package com.pingyijinren.test; import android.content.Intent; import android.support.v7.app.AppCompa ...

  2. poj_2586_Y2K Accounting Bug_201407211318

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10210   Accepted: 50 ...

  3. JSTL-格式标签库

    主页:http://www.cnblogs.com/EasonJim/p/6958992.html的分支页. 一.<fmt:formatNumber> <fmt:formatNumb ...

  4. js 计算获取鼠标相对某个点的移动旋转角度

    // 旋转角度 function getAngle(cen, first, second) { // cen : 中心点 [0,0] // first : 开始点 [1,3] // second : ...

  5. 【c++】C语言中volatile关键字的作用

    因为访问寄存器要比访问内存单元快的多,所以编译器一般都会作减少存取内存的优化,但有可能会读脏数据.当要求使用volatile声明变量值的时候,系统总是重新从它所在的内存读取数据,即使它前面的指令刚刚从 ...

  6. Guass列主元、平方根法、追赶法求解方程组的C++实现

    一,要解决的问题 选用合适的算法,求解三种线性方程组:一般线性方程组,对称正定方程组,三对角线性方程组. 方程略. 二,数值方法 1,使用Guass列主元消去法求解一般线性方程组. Guass列主元是 ...

  7. Maven具体解释之仓库------本地仓库、远程仓库

    在Maven中,不论什么一个依赖.插件或者项目构建的输出.都能够称之为构件. Maven在某个统一的位置存储全部项目的共享的构件.这个统一的位置.我们就称之为仓库.(仓库就是存放依赖和插件的地方) 不 ...

  8. Maven+Mybatis+Spring+SpringMVC实现分页查询(附源代码)

    以下小宝鸽将分享一篇Mybatis分页功能的博文,以下将给出具体的步骤.跟着博主的节奏肯定能实现.另外最后还会附上整个project的源代码.假设是没有使用过maven的猿友可自行下载相关的jar包就 ...

  9. Broccoli &amp; Babel使用演示样例

    1 创建项目project文件夹:test 2 在test下运行 npm init 按提示填写package.json文件 3 安装broccoli命令行工具broccoli-cli npm inst ...

  10. Python按行输出文件内容具体解释及延伸

    下面两端測试代码分别为笔者所写,第一段为错误版本号.后者为正确版本号: #! /usr/bin/python2.7 try:     filename = raw_input('please inpu ...