HDU 6130 Kolakoski

Kolakoski

思路:

从前往后扩展,前后构成映射关系。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define  mem(a,b) memset((a),(b),sizeof(a))
const int N=1e7+5;
int dp[N]={1,2,2,1};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    int i=0,j=0; 
    
    while(j<N)
    {
        for(int k=0;k<dp[i];k++)
        {
            dp[j++]=t;
        } 
        if(t==2)t=1;
        else t=2;
        i++;
    }
    
    cin>>t;
    int n;
    while(t--)
    {
        cin>>n;
        cout<<dp[n-1]<<endl;
    }
    return 0;
} 
原文地址:https://www.cnblogs.com/widsom/p/7365843.html