zoukankan      html  css  js  c++  java
  • 2017 Multi-University Training Contest 7 hdu 6130

    HDU - 6130

    题意:以下是Kolakoski数列:$1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……$,这个数列仅有11和22组成,并且第一项是11。同时还满足一个性质,如果把相邻且相同的项看成一组,可以得到$1,22,11,2,1,22,1,22,11,2,11,22,1……$,计算每一组项的数量,则能得到这个序列本身。这个数列是可以被唯一确定的,请求出它的第nn项。1leq nleq10^71n107​​。

    思路:考虑如何模拟数列的构造,只要在拿一个指针在序列中间扫的同时,往序列末端加数就可以了。

    AC代码:

    #include "iostream"
    #include "iomanip"
    #include "string.h"
    #include "stack"
    #include "queue"
    #include "string"
    #include "vector"
    #include "set"
    #include "map"
    #include "algorithm"
    #include "stdio.h"
    #include "math.h"
    #pragma comment(linker, "/STACK:102400000,102400000")
    #define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
    #define mem(a,x) memset(a,x,sizeof(a))
    #define step(x) fixed<< setprecision(x)<<
    #define mp(x,y) make_pair(x,y)
    #define pb(x) push_back(x)
    #define ll long long
    #define endl ("
    ")
    #define ft first
    #define sd second
    #define lrt (rt<<1)
    #define rrt (rt<<1|1)
    using namespace std;
    const long long INF = 1e18+1LL;
    const int inf = 1e9+1e8;
    const int N=1e7+100;
    const ll mod=1e9+7;
    const double PI=acos(-1.0);
    
    int Kol[N+5]={0,1,2,2};
    void init(){
        int t=2,k=2; //t表示当前i在第t块,k表示当前i是第t块的第k个数
        for(int i=3; i<=N; ++i){
            if(Kol[t]==2){
                if(k==1){
                    if(Kol[i-1]==1){
                        Kol[i]=2;
                    }
                    else Kol[i]=1;
                    k=2;
                }
                else if(k==2){
                    if(Kol[i-1]==1){
                        Kol[i]=1;
                    }
                    else Kol[i]=2;
                    k=1; t++;
                }
            }
            else{
                if(Kol[i-1]==1){
                    Kol[i]=2;
                }
                else Kol[i]=1;
                k=1; t++;
            }
        }
    }
    
    int main(){
        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
        init();
        int T; cin>>T;
        while(T--){
            int n; cin>>n;
            cout<<Kol[n]<<endl;
        }
        return 0;
    }
  • 相关阅读:
    PostgreSQL锁级别及什么操作获取什么锁
    python类和实例
    使用@property
    python3基础笔记(六)模块与包
    【转载】Python装饰器-专题笔记
    python3基础笔记(五)迭代器与生成器
    python3基础笔记(四)文件处理
    python3基础笔记(三)函数与全局、局部变量
    python3基础笔记(二)python的基本数据类型与运算符
    python3基础笔记(一)
  • 原文地址:https://www.cnblogs.com/max88888888/p/7367949.html
Copyright © 2011-2022 走看看