ACM模版

描述

题解

这个题就是一个数列的第 n 项是多少,简单的来就是预处理出来直接输出就行了……有些比较玄学的解法是直接一行输出……莫名其妙的,看他们的代码连样例都过不去,但是竟然 AC ……我有些难以置信。

代码

#include <iostream>

using namespace std;

const int MAXN = 1e7 + 10;

int n;
int a[MAXN] = {
  0, 1, 2};

void init()
{
    int t = 2;
    for (int i = 2; i < MAXN; i++)
    {
        for (int j = t + 1; j <= t + a[i] - 1; j++)
        {
            a[j] = a[j - 1];
        }
        t = t + a[i];
        if (a[t - 1] == 1)
        {
            a[t] = 2;
        }
        else
        {
            a[t] = 1;
        }
        if (t > MAXN)
        {
            break;
        }
    }
}

int main(int argc, const char * argv[])
{
    init();

    int T;
    cin >> T;
    while (T--)
    {
        cin >> n;
        cout << a[n] << '\n';
    }

    return 0;
}