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

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. 记一次rsync增量同步远程服务器文件

    rsync remote shell 增量方式同步数据 rsync同步文件有两种方式,一种是daemon的方式(rsync daemon)另一种方式是通过远程shell方式(rsync remote ...

  2. JS性能方面--内存管理及ECMAScript5 Object的新属性方法

    Delete一个Object的属性会让此对象变慢(多耗费15倍的内存) var o = { x: 'y' }; delete o.x; //此时o会成一个慢对象 o.x; // var o = { x ...

  3. python 时间类型和相互转换

    time有四种类型(time, datetime, string, timestamp) 1. time string string是最简单的表示time的方式 如如下代码生成的即为string &g ...

  4. llinux 查看自己的公网ip

    如何在LINUX服务器下查看公网IP地址,可以使用下面的方法: [root@web ~]#curl http://members.3322.org/dyndns/getip [root@web ~]# ...

  5. (转)Java中的String为什么是不可变的

    转自:http://www.importnew.com/7440.html String是所有语言中最常用的一个类.我们知道在Java中,String是不可变的.final的.Java在运行时也保存了 ...

  6. xcode 不显示占用内存

    解决办法: Scheme设置中,将 Enable Zombie Objects 勾选去掉.

  7. Bitcask 存储模型

    Bitcask 存储模型 Bitcask 是一个日志型.基于hash表结构的key-value存储模型,以Bitcask为存储模型的K-V系统有 Riak和 beansdb新版本. 日志型数据存储 何 ...

  8. Lucene.Net+盘古分词->开发自己的搜索引擎

    //封装类 using System;using System.Collections.Generic;using System.Linq;using System.Web;using Lucene. ...

  9. js实现99乘法表

    实现99乘法表(输出到页面上) * document.write("<table border='1' bordercolor='blue'>"); //循环行 9 f ...

  10. Html.RenderPartial、Html.RenderAction联系与区别

    1.引言 开发人员经常希望应用程序可以在多个不同的地方使用同样的Razor标签和HTML标记代码.这并不需要我们在多个地方重复这些标签,使用MVC中的分部视图和子动作可以让我们很好的解决类似的情况. ...