zoukankan      html  css  js  c++  java
  • 2017杭电多校第七场1011Kolakoski

    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(1T5), denoting the number of test cases.
    For each test case:
    A single line contains a positive integer n(1n107).
     

    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;
    }


  • 相关阅读:
    VIM常用操作
    计算机之二进制基础
    交换机安全学习笔记 第六章 IPV4 ARP攻击
    交换机安全学习笔记 第八章 针对POE的攻击
    交换机安全学习笔记 第九~十章 HSRP VRRP
    CSRF-DVWA_1.9-笔记
    命令注入-笔记
    暴力破解-H3C路由器-MSR900
    暴力破解-DVWA_1.9-笔记
    DVWA、 DSVM 环境搭建简述
  • 原文地址:https://www.cnblogs.com/bryce1010/p/9387396.html
Copyright © 2011-2022 走看看