Chieh's Blog

Because Of Coding

ZOJ Problem Set - 2273 Number Sequence III

Chieh posted @ 2015年8月24日 12:51 in NO Answer No Speak , 203 阅读
/*
Author:Chieh
Because Of Coding
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <stack>
#include <set>
#define LL long long
#define INF 1e9
#define EPS 1e-9
using namespace std;
int len[100000];
int Link[11];
int idx[11];
int  Get(int x,int y)
{

    while(1)
    {
        int ys=x%10;
        x/=10;
        y--;
        if(y==0)return ys;
    }
}
void init()
{

    Link[1]=1;
    int p=2;
    for(int i=2; i<=10; i++)
    {
        Link[i]=Link[i-1]+p;
        p*=2;
        p*=2;
    }
    int st=1;
    int bef=0;
    for(int i=1; i<=99999; i++)
    {
        int t;
        if(i>=10000)t=5;
        else if(i>=1000)t=4;
        else if(i>=100)t=3;
        else if(i>=10)t=2;
        else t=1;
        int now=bef+t;
        if(st<=10&&now>=Link[st])
        {
            int xi=Link[st]-bef;
            idx[st]=Get(i,t-xi+1);
            st++;
        }
        len[i]=idx[st-1];
        bef=now;
    }
}
int n;
void play()
{
    printf("%d\n",len[n]);
}
int main()
{
    init();
    while(scanf("%d",&n)!=EOF){
        play();
    }
    // cout << "Hello world!" << endl;
    return 0;
}

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter