HDU - 6130 Kolakoski (打表)

题意:由1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1,……合并可得1,22,11,2,1,22,1,22,11,2,11,22,1,再由每个数的位数可得新序列,推出新序列第n项。

分析:新序列与原序列相同,按题意打表即可。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
    if(fabs(a - b) < eps) return 0;
    return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 10000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
vector<int> v;
int main(){
    v.push_back(1);
    v.push_back(2);
    v.push_back(2);
    v.push_back(1);
    v.push_back(1);
    int cur = 3;
    while(1){
        int cnt = v[cur];
        int x;
        if(v.size() & 1){
            x = 2;
        }
        else{
            x = 1;
        }
        for(int i = 0; i < cnt; ++i){
            v.push_back(x);
        }
        if(v.size() > 10000000) break;
    }
    int T;
    scanf("%d", &T);
    while(T--){
        int n;
        scanf("%d", &n);
        printf("%d\n", v[n - 1]);
    }
    return 0;
}

 

posted @ 2017-08-15 21:20  Somnuspoppy  阅读(244)  评论(0编辑  收藏  举报