找规律,先找属于第几个循环,再找属于第几个数的第几位。。。。。。

Number Sequence
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 31552 Accepted: 8963

Description

A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consists of a sequence of positive integer numbers ranging from 1 to k, written one after another. 
For example, the first 80 digits of the sequence are as follows: 
11212312341234512345612345671234567812345678912345678910123456789101112345678910

Input

The first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by one line for each test case. The line for a test case contains the single integer i (1 ≤ i ≤ 2147483647)

Output

There should be one output line per test case containing the digit located in the position i.

Sample Input

2
8
3

Sample Output

2
2

Source

Tehran 2002, First Iran Nationwide Internet Programming Contest

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

inline int getlen(int x)
{
    return log10(1.0*x)+1;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int pos,th,kth=0,x=1,nth=0,i;
        scanf("%d",&pos); th=pos;
        while(pos>0)
        {
            kth+=getlen(x);
            pos-=kth;
            x++;
        }
        x=x-1; pos=pos+kth;
        for(i=1;i<=x;i++)
        {
            nth+=getlen(i);
            if(nth>=pos)
                break;
        }
        nth-=getlen(i);
        int deta=pos-nth;
        int bit[10],ii=0;
        while(i)
        {
            bit[ii++]=i%10;;
            i/=10;
        }
        printf("%d\n",bit[ii-deta]);
    }
    return 0;
}

/*   有爱的测试数据。。。
            1
            1
            2
            1
            2//5
            3
            1
            2
            3
            4//10
            1
            2
            3
            4
            5//15
            1
            2
            3
            4
            5//20
            6
            1
            2
            3
            4//25
            5
            6
            7
            1
            2//30
            3
            4
            5
            6
            7//35
            8
            1
            2
            3
            4//40
            5
            6
            7
            8
            9//45
            1
            2
            3
            4
            5//50
            6
            7
            8
            9
            1//55
            0
            1
            2
            3
            4//60
            5
            6
            7
            8
            9//65
            1
            0
            1
            1
            1//70
            2
            3
            4
            5
            6//75
            7
            8
            9
            1
            0//80
*/

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

POJ 1019 Number Sequence的更多相关文章

  1. Poj 1019 Number Sequence( 数据分析和操作)

    一.题目大意 有这样一个序列包含S1,S2,S3...SK,每一个Si包括整数1到 i.求在这个序列中给定的整数n为下标的数. 例如,前80位为1121231234123451234561234567 ...

  2. poj 1019 Number Sequence 【组合数学+数字x的位宽函数】

    题目地址:http://poj.org/problem?id=1019 Number Sequence Time Limit: 1000MS   Memory Limit: 10000K Total ...

  3. POJ 1019 Number Sequence 解读

    这是一个看似简单,其实很难受. 本来我想发挥它的标题轨道基础.没想到反被消遣-_-|||. 看它在个人基础上,良好的数学就干脆点,但由于过于频繁,需求将被纳入全,因此,应该难度4星以上. 方法就是直接 ...

  4. POJ - 1019 Number Sequence (思维)

    https://vjudge.net/problem/POJ-1019 题意 给一串1 12 123 1234 12345 123456 1234567 12345678 123456789 1234 ...

  5. PKU 1019 Number Sequence(模拟,思维)

    题目 以下思路参考自discuss:http://poj.org/showmessage?message_id=176353 /*我的思路: 1.将长串数分成一个个部分,每个部分是从1到x的无重复的数 ...

  6. POJ 1019:Number Sequence 二分查找

    Number Sequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36013   Accepted: 10409 ...

  7. HDU 1005 Number Sequence

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  8. hdu 1005:Number Sequence(水题)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. hdu1005 Number Sequence(寻找循环节)

    主题链接: pid=1005">huangjing 题意: 就是给了一个公式,然后求出第n项是多少... 思路: 题目中n的范围实在是太大,所以肯定直接递推肯定会超时,所以想到的是暴力 ...

随机推荐

  1. 《JavaScript权威指南》学习笔记 第七天 DOM操作

    由衷的觉得,随着IT技术的广泛的运用,个人电脑以及智能手机的使用,信息的获取与传播更为简单.但是我们获取有用信息的难度相反是越来越大了,想要保持住自己的注意力越来越难了.除了吃饭睡觉,我的精力都在电脑 ...

  2. 捉襟见肘之UIViewAnimationOptions

    [UIView animateWithDuration:duration delay:0.0f options:(curve << | UIViewAnimationOptionBegin ...

  3. 菜鸟之linux问题之图形界面和dos界面的登录问题

    1.安装完linux系统后,图形化界面的用户名和密码是之前安装的时候设置的. 如果想切换到linux的dos窗口快捷键是:ctrl+alt+F2 由dos窗口切换到linux图形界面快捷键是:ctrl ...

  4. c语言程序

    汇编语言嵌入到c语言中 #include<stdio.h> int main(void) { int a,b,c; a=4; b=5; _asm { mov eax,a; add eax, ...

  5. SVM松弛变量-记录毕业论文3

    上一篇博客讨论了高维映射和核函数,也通过例子说明了将特征向量映射到高维空间中可以使其线性可分.然而,很多情况下的高维映射并不能保证线性可分,这时就可以通过加入松弛变量放松约束条件.同样这次的记录仍然通 ...

  6. 批处理学习:for语句详解【经典】

    大纲 一 前言 二 for语句的基本用法 三 for /f (delims.tokens.skip.eol.userbackq.变量延迟) 四 for /r (递归遍历) 五 for /d (遍历目录 ...

  7. ./yy.sh -d bash 执行脚本时所加的参数

    -e filename 如果 filename存在,则为真 -d filename 如果 filename为目录,则为真 -f filename 如果 filename为常规文件,则为真 -L fil ...

  8. 9月9日下午HTML样式表(宽度和高度、背景字体、对齐方式边界与边框)

    样式表 一.大小 1.width   宽度 2.height  高度 <div style="width:200px; height:200px"></div&g ...

  9. Spring MVC学习笔记——用户增删该查和服务器端验证

    建立一个动态web项目,起名为SpringMVC_crud 导包,其中包括jstl的一些包等 1.先写一个User.java,是用户类 文件User.java文件 package org.common ...

  10. CSS 中背景图片定位方法

    三种: 关键字:background-position: top left; 像素:background-position: 0px 0px; 百分比:background-position: 0% ...