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

            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)  編輯 收藏 引用

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

            導航

            統計

            常用鏈接

            留言簿

            文章檔案(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
            • 評論內容較長,點擊標題查看
            • --王私江
            亚洲国产精品无码久久一线| 久久久无码精品午夜| 香蕉久久夜色精品国产小说| 国产精品gz久久久| 香蕉久久AⅤ一区二区三区| 精品国产乱码久久久久久1区2区| 亚洲va中文字幕无码久久不卡| 久久精品桃花综合| 亚洲精品WWW久久久久久| 久久一区二区免费播放| 69久久夜色精品国产69| 精品久久777| 日韩AV无码久久一区二区| 久久精品亚洲精品国产欧美| 狠狠综合久久综合88亚洲| 精品国产91久久久久久久| 久久久久无码精品| 久久天天躁狠狠躁夜夜96流白浆| 亚洲成色www久久网站夜月| 久久亚洲国产精品123区| 久久免费观看视频| 国产精品久久亚洲不卡动漫| 2021国产精品午夜久久| 久久久久中文字幕| 国产午夜福利精品久久2021| 欧美日韩精品久久久免费观看| 2021国内久久精品| 2021久久精品国产99国产精品| 国产日韩久久免费影院| 久久香综合精品久久伊人| 久久99免费视频| …久久精品99久久香蕉国产| 久久久高清免费视频| 国内精品久久久久久久久电影网 | 亚洲精品乱码久久久久久| 午夜天堂av天堂久久久| 久久久久免费精品国产| 99久久精品九九亚洲精品| 久久国产视频99电影| 91久久精品视频| 99精品久久久久久久婷婷|