hdu 1597 find the nth digit (数学)

find the nth digit

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7403    Accepted Submission(s): 2120


Problem Description
假设:
S1 = 1
S2 = 12
S3 = 123
S4 = 1234
.........
S9 = 123456789
S10 = 1234567891
S11 = 12345678912
............
S18 = 123456789123456789
..................
现在我们把所有的串连接起来
S = 1121231234.......123456789123456789112345678912.........
那么你能告诉我在S串中的第N个数字是多少吗?
 
Input
输入首先是一个数字K,代表有K次询问。
接下来的K行每行有一个整数N(1 <= N < 2^31)。
 
Output
对于每个N,输出S中第N个对应的数字.
 
Sample Input
6 1 2 3 4 5 10
 
Sample Output
1 1 2 1 2 4
 
Author
8600
 
Source
 
Recommend
8600   |   We have carefully selected several similar problems for you:  1595 1016 1599 1677 1598 
 
 1 //453MS    256K    301 B    C++
 2 /*
 3 
 4     题意:
 5         中文,找规律下第n个数是什么
 6         
 7     数学规律:
 8         其实早该看出该规律了..不过暴力的话应该会TLE才对...
 9         用二分法找那个数应该不会TLE才对....
10         后来都试过了..都会TLE,加个中间变量又不会TLE...
11         略感无解...
12          
13 */
14 #include<stdio.h>
15 int main(void)
16 {
17     int t,n;
18     scanf("%d",&t);
19     while(t--)
20     {
21         scanf("%d",&n);
22         int a=1;
23         int m=n;
24         while(m>a){
25             m-=a;
26             a++; 
27         }       
28         printf("%d
",m%9==0?9:m%9);    
29     }
30     return 0;
31 }
原文地址:https://www.cnblogs.com/GO-NO-1/p/3428780.html