• <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ù)字
            然后再求,
            直接寫瘋了這次,寫了一天了
            還是沒調(diào)出來
            果斷刪掉
            去網(wǎng)上找題解
            直接用digit記錄123……n的數(shù)字個數(shù),len記錄連續(xù)個這個12……n的總長
            然后查找到這個數(shù)
            然后在構(gòu)造出來,直接查就行了
            不過速度沒法比

            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

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內(nèi)容較長,點(diǎn)擊標(biāo)題查看
            • --王私江
            2021国产成人精品久久| 日韩va亚洲va欧美va久久| 国内精品人妻无码久久久影院| 日韩久久久久久中文人妻| 国产精品久久久天天影视香蕉| 亚洲精品国精品久久99热| 久久香蕉国产线看观看精品yw| 亚洲国产精品久久久久| 久久99热这里只有精品66| 69久久夜色精品国产69| 香蕉久久AⅤ一区二区三区| 久久久久免费看成人影片| 色播久久人人爽人人爽人人片aV| 国产精品美女久久久m| 囯产极品美女高潮无套久久久| 国产精品欧美亚洲韩国日本久久| 色综合久久久久久久久五月| 久久亚洲中文字幕精品一区四| 波多野结衣中文字幕久久| 狠狠色丁香久久婷婷综合| 亚洲精品综合久久| 国内精品久久久久久久久电影网| 国产产无码乱码精品久久鸭| 99精品国产综合久久久久五月天| 久久最新免费视频| 久久久久亚洲?V成人无码| 久久99久久99小草精品免视看| 久久精品天天中文字幕人妻| 国产欧美久久久精品影院| 亚洲午夜久久久| 精品伊人久久久| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 色88久久久久高潮综合影院| 久久男人AV资源网站| 久久久久女教师免费一区| 国产午夜福利精品久久| 久久国产精品久久久| 久久精品免费一区二区三区| 69久久精品无码一区二区| 91久久精品国产免费直播| 天天爽天天爽天天片a久久网|