POJ 1019 Number Sequence

Source: Internet
Author: User

Title: http://poj.org/problem?id=1019

Solution:

Preprocess the length of $cnt (i) $ for $s_i$, $S (i) $ for $cnt (i) $ for the prefix and, in this case, for a coordinate n, to get a string of length n, we can divide it into $s_1,s_2....s_{k-1}$ and not necessarily complete $s_k$. Dichotomy $s (i) $ with $n$ minus the corresponding $s (t) $ to get the length of the incomplete string $s_k$

Next, the $s_k$ is divided into two parts, part of which is the complete number, and part of it is not necessarily a complete number. For example: 1 and 10 in 1234567891,12345678910, and the same treatment as above.

The problem is converted to the T-bit of the number x, which can be simulated.

#include <cstdio>#include<cstring>#include<cmath>#defineN 100010#defineLD Double#defineLL Long Longusing namespacestd;intCnt[n],tot,num[n]; LL S[n];intGet_num (intXintt) {Tot=0;  for(intI=x;i;i/=Ten) num[++tot]=i%Ten; returnnum[tot-t+1];}intCalcintN) {     for(intI=1; i<n;i++)        if(n<=S[i]) {N-=s[i-1];  Break; }    intIPOs;  for(intI=1; i<n;i++)        if(n<=Cnt[i]) {N-=cnt[i-1]; IPOs=i;  Break; }    returnGet_num (ipos,n);}intMain () { for(intI=1; i<n;i++) {Cnt[i]=cnt[i-1]+(int) log10 ((LD) i) +1; S[i]=s[i-1]+Cnt[i]; }    intT,n; scanf ("%d",&T);  while(t--) {scanf ("%d",&N); printf ("%d\n", Calc (n)); }    return 0;}
View Code

POJ 1019 Number Sequence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.