POJ 1019 Number Sequence

求解思路:
  1 求解该位置所在的循环序列 Line:14~16
  2 求解该位置数的位数 Line:17
  3 求解该位置的数 Line:18
  4求解该数的的对应位置的数值
   
     
1 #include < iostream >
2 #include < cmath >
3   using namespace std;
4 #define EPS 1e-6
5 int main()
6 {
7 int i,j,n,m,r,l,p,b[] = { 0 , 45 , 9000 , 1386450 , 188019000 };
8 int c[] = { 0 , 9 , 189 , 2889 , 38889 };
9 double t;
10 scanf( " %d " , & n);
11 while (n -- )
12 {
13 scanf( " %d " , & m);
14 for (i = 1 ;i < 5 && b[i] < m;i ++ )m -= b[i];
15 t = sqrt(pow(i + 2 * c[i - 1 ], 2.0 ) + 8 * i * double (m)) - (i + 2 * c[i - 1 ]);
16 t /= ( 2 * i);l = t - EPS;m -= l * c[i - 1 ] + (l * (l + 1 ) / 2 ) * i;
17 for (r = j = 1 ;j < i && m > c[j];j ++ ,r *= 10 );m -= c[j - 1 ];
18 l = (m - 1 ) / j;m -= l * j;p = l + r;
19 for (i = 1 ;i <= j - m;i ++ )p /= 10 ;
20 printf( " %d\n " ,p - p / 10 * 10 );
21 }
22 return 0 ;
23 }

 

你可能感兴趣的:(sequence)