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

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. java里面时间差比较

    currentTime.before(this.getLastActivateTime(time))//返回true 或者false public Date getLastActivateTime(t ...

  2. ASP.NET MVC 给ViewBag赋值Html格式字符串的显示问题总结

    今天再给自己总结一下,关于ViewBag赋值Html格式值,但是在web页显示不正常; 例如,ViewBag.Content = "<p>你好,我现在测试一个东西.</p& ...

  3. JS, Node.js, npm简介

    序 听过JS,听过Node,也听过Node.js,还听过npm,然而并不是很清楚的知道都代表什么,这两天调接口,然后前端同学很忙,就自己把前端代码拿过来跑了,也趁机了解一下这几个概念,下边做个小的总结 ...

  4. Java synchronized指南

    在多线程程序中,同步修饰符用来控制对临界区代码的访问.其中一种方式是用synchronized关键字来保证代码的线程安全性.在Java中,synchronized修饰的代码块或方法不会被多个线程并发访 ...

  5. 【Alpha版本】冲刺-Day6

    队伍:606notconnected 会议时间:11月14日 会议总结 张斯巍(433) 今天安排:学习UI设计 完成度:100% 明天计划:上传界面设计 遇到的问题:无 感想:刚开始学的时候,都是从 ...

  6. Mysql备份还原数据库之mysqldump实例及参数详细说明

    [root@localhost myexport]# mysqldump -h211.100.75.204 -uroot -p@^#coopen -P5029 --single-transaction ...

  7. JPA事务总结

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

  8. Git连接到自己的GitHub仓库

    1.配置本地git $git config --global user.name "xxx" $git config --global user.email "xxxxx ...

  9. RestSharp使用

    class Program { private readonly static string investRankingForAllUrl = "http://192.168.1.98:90 ...

  10. JQuery------判断拥有某个class或id的div是否存在

    if ($(".Btn,#Show").length > 0) { alert("存在"); } else { alert("不存在" ...