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

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 单线程相关

    众所周知,Javascript是单线程执行的,这也就是说:JavaScript在同一个时间上只能处理一件事.他不像C,Java等这些多线程的,可以开不同的线程去同时处理多件事情. 那么为什么别的语言都 ...

  2. [JavaEE] Entity中Lazy Load的属性序列化JSON时报错

    The server encountered an internal error that prevented it from fulfilling this request.org.springfr ...

  3. 数据结构与算法分析 - 最短路(Dijkstra+floyd_Warshall+bellman_ford)

    先附上Djikstra的代码:普通版 const int maxn=101; const int INF=0x3f3f3f3f; int edges[maxn][maxn]; int dist[max ...

  4. JPA事务总结

    http://www.soso.io/article/65405.html 事务管理是JPA中另一项重要的内容,了解了JPA中的事务管理,能够进一步掌握JPA的使用.事务管理是对一系列操作的管理,它最 ...

  5. JavaScript DES 加密tripledes.js:

    <html> <head> <meta http-equiv="content-type" content="text/html; char ...

  6. html代码规范

    HTML代码规范   我们知道,前端工程师入门容易,通过学习基本的HTML和CSS就能在浏览器上看到实际的效果,可是要写好的HTML,就不是那么容易了.这里将和大家分享HTML规范,希望大家读完之后都 ...

  7. vs------各种错误解决方法

    错误:命名空间System.Net中不存在类型或命名空间名“Http”,或工程里面“引用”的文件太少 转载:http://www.asp.net/mvc/mvc4 错误:LD.exe 已退出,代码为- ...

  8. CentOS6.5 安装Sphinx 配置MySQL数据源

      前提安装完mysql,并创建测试表和数据 DROP TABLE IF EXISTS `documents`; CREATE TABLE IF NOT EXISTS `documents` ( `i ...

  9. 10月21上午PHP基础

    新建的php文件必须要放在wamp安装目录下的www文件夹里.如果拿到别的地方,php无法运行,将显示错误. <?php?> //嵌入php的方式 <?php //嵌入php方式的开 ...

  10. pulltorefresh滚动到底部

    如果用ListView,让它滚动到顶部,一般是这样写的: if (!listView.isStackFromBottom()) { listView.setStackFromBottom(true); ...