• <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)題查看
            • --王私江
            久久人人爽人人爽人人片av高请| 色综合久久88色综合天天 | 伊人色综合九久久天天蜜桃| 久久一日本道色综合久久| 69国产成人综合久久精品| 久久精品中文字幕有码| 久久丫忘忧草产品| 伊人久久综合热线大杳蕉下载| 久久精品中文字幕第23页| 欧美牲交A欧牲交aⅴ久久| 久久国产精品波多野结衣AV| 久久亚洲私人国产精品| 性高朝久久久久久久久久| 久久久国产精品网站| 中文字幕人妻色偷偷久久| 久久www免费人成精品香蕉| 久久66热人妻偷产精品9| 国产精品久久久久a影院| 久久电影网2021| 99re这里只有精品热久久| 亚洲AV无码1区2区久久| 亚洲欧美国产精品专区久久 | 久久99国产精品99久久| 精品多毛少妇人妻AV免费久久 | 免费观看成人久久网免费观看| 亚洲va久久久久| 久久夜色精品国产www| 亚洲国产成人久久综合碰碰动漫3d| 中文字幕无码精品亚洲资源网久久| 久久99国产一区二区三区| 国内精品久久久久久久亚洲| 99久久精品国产一区二区三区 | 久久久久亚洲精品天堂| 久久国产精品无| 久久香综合精品久久伊人| 久久婷婷国产剧情内射白浆| 久久精品一区二区三区AV| 久久精品成人国产午夜| 国产高潮国产高潮久久久91 | 久久综合久久综合亚洲| 久久综合偷偷噜噜噜色|