• <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 閱讀(217) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


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

            導(dǎo)航

            統(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
            • 評論內(nèi)容較長,點擊標題查看
            • --王私江
            久久亚洲国产成人精品无码区| 人妻无码久久精品| 伊人久久久AV老熟妇色| 久久综合亚洲色HEZYO社区 | 国产精品久久久久9999高清| 久久中文骚妇内射| 亚洲午夜精品久久久久久人妖| 久久亚洲精品视频| 亚洲国产成人久久一区久久| 精品国产青草久久久久福利| 丰满少妇人妻久久久久久| 99久久精品国产一区二区蜜芽 | 99蜜桃臀久久久欧美精品网站| 亚洲AV成人无码久久精品老人| 国产成人精品久久免费动漫| 久久久久99精品成人片三人毛片| 性色欲网站人妻丰满中文久久不卡| 热re99久久精品国产99热| 久久人妻少妇嫩草AV无码蜜桃| 少妇内射兰兰久久| 精品久久国产一区二区三区香蕉 | 亚洲精品国产第一综合99久久 | 久久久受www免费人成| 精品久久久中文字幕人妻 | 18岁日韩内射颜射午夜久久成人 | 香蕉99久久国产综合精品宅男自| 久久夜色精品国产噜噜麻豆 | 亚洲国产二区三区久久| 久久午夜夜伦鲁鲁片免费无码影视 | 久久精品国产99久久香蕉| 国产精品国色综合久久| 久久人人添人人爽添人人片牛牛| 大美女久久久久久j久久| 东京热TOKYO综合久久精品| 久久亚洲精品无码aⅴ大香| 久久久久久亚洲精品无码| 国产激情久久久久影院老熟女免费| 久久久免费精品re6| 久久国产亚洲精品无码| 99久久成人国产精品免费| 狠狠色丁香久久婷婷综合|