POJ1019-Number Sequence-数数。。

1

12

123

1234

把数按照这样的形式拍成一排,给一个序号求出那个序号对应的数。

当出现两位数。三位数时,要麻烦的处理一下。

#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int T,N,ans;

int getbit(int x)
{
    int rtn = 0;
    while(x)
    {
        x/=10;
        rtn++;
    }
    return rtn;
}

int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&N);
        int cur = 1,cnt = 1;;
        while(true)
        {
            if(N <= cur) break;
            N -= cur;
            cnt++;
            cur += getbit(cnt);
        }
        //printf("N=%d cur=%d cnt=%d\n",N,cur,cnt);
        cur = 1,cnt = 1;
        while(true)
        {
            if(N <= cur) break;
            N -= cur;
            cnt++;
            cur = getbit(cnt);
        }
        //printf("N=%d cur=%d cnt=%d\n",N,cur,cnt);

        if(cur == N) ans = cnt%10;
        else ans = (int)(cnt/pow(10,cur-N)) % 10;
        printf("%d\n",ans);
    }
}
时间: 2025-01-06 16:36:59

POJ1019-Number Sequence-数数。。的相关文章

POJ1019——Number Sequence(大数处理)

Number Sequence DescriptionA 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 t

POJ1019 Number Sequence

Number Sequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36256   Accepted: 10461 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..

求序列中满足Ai &lt; Aj &gt; Ak and i &lt; j &lt; k的组数 树状数组 HIT 2275 Number sequence

http://acm.hit.edu.cn/hoj/problem/view?id=2275 Number sequence   Source : SCU Programming Contest 2006 Final   Time limit : 1 sec   Memory limit : 64 M Submitted : 1632, Accepted : 440 Given a number sequence which has N element(s), please calculate

Minimum Inversion Number 【线段数】

Problem DescriptionThe inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i < j and ai > aj. For a given sequence of numbers a1, a2, ..., an, if we move the first m >= 0 numbers to the end of

poj1019(Number Sequence)

题目地址:Number Sequence 题目大意: 有一串序列由阿拉伯数字够成11212312341234512345612345671234567812345678912345678910123456789101112345678910.......然后问你第几位数字是什么输出该数字. 解题思路: 排列组合.假如算第79位数字为多少,先计算出它在那个1-n的区间,可以看出79在1-12这段数字的区间,然后计算出前面1.1-2.1-3....1-11所有数的总和有多少位减去之后,再通过模拟在1

hdoj 1394 Minimum Inversion Number 【线段数】

题目大意:求移动数列中的第一个元素到最后一位时的最少逆序数.(进行n次移动,求移动过程中最少的逆序数) 难点: 一:什么是逆序数? 定义: 在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序.一个排列中逆序的总数就称为这个排列的逆序数.逆序数为偶数的排列称为偶排列:逆序数为奇数的排列称为奇排列.如2431中,21,43,41,31是逆序,逆序数是4,为偶排列. 二:怎么求? 此题分析一下有个技巧:对于这道题因为是0~n-1所以我们可以通过下标就可以判

[LeetCode] 248. Strobogrammatic Number III 对称数III

A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Write a function to count the total strobogrammatic numbers that exist in the range of low <= num <= high. For example,Given low = "50&qu

[LeetCode] 247. Strobogrammatic Number II 对称数II

A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Find all strobogrammatic numbers that are of length = n. For example,Given n = 2, return ["11","69","88","96"

[LeetCode] 260. Single Number III 单独数 III

Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. Example: Input: [1,2,1,3,2,5] Output: [3,5] Note: The order of the result is

hdu5014 Number Sequence(异或运算)

题目链接: huangjing 题意: 这个题目的意思是给出0~n的排列,然后找出与这个序列的配对使(a0 ⊕ b0) + (a1 ⊕ b1) +·+ (an ⊕ bn)最大.. 思路: 从大到小遍历每个数,然后找到与这个数二进制位数互补的数,那么他们的抑或值必定是pow(2,n)-1,,肯定是最大的.... 题目: Number Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav