• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            poj1019

            Number Sequence

            Time Limit: 1000MS
            Memory Limit: 10000K
            Total Submissions: 27759
            Accepted: 7661

            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

            寫了一整天

            開始想先把1-1位數(shù),1-2位數(shù), 1-3位數(shù),1-4位數(shù)的那個都算出來,然后減去
            然后確定是那些中的
            然后再確定是那一個的和中的
            然后在確定數(shù)字
            然后再求,
            直接寫瘋了這次,寫了一天了
            還是沒調出來
            果斷刪掉
            去網上找題解
            直接用digit記錄123……n的數(shù)字個數(shù),len記錄連續(xù)個這個12……n的總長
            然后查找到這個數(shù)
            然后在構造出來,直接查就行了
            不過速度沒法比

            code
            #include <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <ctime>
            #include 
            <cassert>
            #include 
            <iostream>
            #include 
            <sstream>
            #include 
            <fstream>
            #include 
            <map>
            #include 
            <set>
            #include 
            <vector>
            #include 
            <queue>
            #include 
            <algorithm>
            #include 
            <iomanip>
            using namespace std;

            const int maxsize=100010;
            long long digit[maxsize],len[maxsize];
            stringstream ss;
            void init()
            {
                
            int i;
                digit[
            1]=len[1]=1;
                
            for(i=2;i<maxsize;i++)
                
            {
                    digit[i]
            =digit[i-1]+(int)log10(double(i))+1;
                    len[i]
            =len[i-1]+digit[i];
                }

            }

            char getdigit(int num)
            {
                
            int i;
                
            for(i=1;len[i]<num;i++);
                
            int pos=num-len[i-1];
                ss.str(
            "");
                
            for(i=1;i<=pos;i++) ss<<i;
                
            return ss.str()[pos-1];
            }

            int main()
            {
                
            int i,sets,num;
                cin
            >>sets;
                init();
                
            while(sets--)
                
            {
                    cin
            >>num;
                    cout
            <<getdigit(num)<<endl;
                }

                
            return 0;
            }




            posted on 2012-07-31 21:28 jh818012 閱讀(218) 評論(0)  編輯 收藏 引用

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統(tǒng)計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內容較長,點擊標題查看
            • --王私江
            久久精品国产亚洲av麻豆图片| 久久综合九色综合网站| 久久亚洲国产中v天仙www| 91久久精品国产91性色也| 热久久视久久精品18| 精品久久久久久亚洲| 久久久久国产视频电影| 亚洲精品第一综合99久久| 国内精品久久久久| 亚洲国产成人久久精品影视| 四虎国产精品成人免费久久| 91视频国产91久久久| 久久人人爽人人爽人人片av麻烦 | 欧美午夜精品久久久久久浪潮| 2021国内久久精品| 国产精品永久久久久久久久久| 久久亚洲私人国产精品| 色婷婷综合久久久久中文字幕| 国产精品久久久久影院嫩草| 色综合久久中文字幕无码| 久久久久亚洲AV无码专区桃色 | 午夜精品久久久久成人| 亚洲伊人久久大香线蕉苏妲己| 久久精品水蜜桃av综合天堂| 久久无码国产专区精品| 亚洲国产高清精品线久久 | 精品国产乱码久久久久久人妻| 日本亚洲色大成网站WWW久久| 久久国产精品免费| 久久精品国产一区二区电影| 97r久久精品国产99国产精| 91精品国产高清久久久久久io| 久久久久久午夜成人影院| 久久偷看各类wc女厕嘘嘘| 久久久无码一区二区三区| 色婷婷综合久久久久中文 | 日韩十八禁一区二区久久| 亚洲精品WWW久久久久久| 久久久久亚洲精品无码网址| 久久精品无码一区二区三区免费| 久久这里有精品视频|