标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 36256 | Accepted: 10461 |
Description
Input
Output
Sample Input
2 8 3
Sample Output
2 2
Source
/* ID: LinKArftc PROG: 1019.cpp LANG: C++ */ #include <map> #include <set> #include <cmath> #include <stack> #include <queue> #include <vector> #include <cstdio> #include <string> #include <utility> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define eps 1e-8 #define randin srand((unsigned int)time(NULL)) #define input freopen("input.txt","r",stdin) #define debug(s) cout << "s = " << s << endl; #define outstars cout << "*************" << endl; const double PI = acos(-1.0); const int inf = 0x3f3f3f3f; const int INF = 0x7fffffff; typedef long long ll; const int maxn = 40000; ll sum[maxn], line[maxn];//分别是前i行的位数和,第i行的位数 int getbit(int x) { return (int)log10((double)x) + 1; } void init() { sum[1] = line[1] = 1; for (int i = 2; i <= 35000; i ++) { line[i] = line[i-1] + getbit(i); sum[i] = sum[i-1] + line[i]; } } int getpos(int x, int pos) { int len = getbit(x); for (int i = 1; i <= len - pos; i ++) x /= 10; return x % 10; } int main() { init(); int T; ll n; scanf("%d", &T); while (T --) { scanf("%lld", &n); int cur = 1; while (sum[cur] < n) cur ++; ll pos = n - sum[cur-1]; while (cur >= 1) { if (pos > line[cur-1]) { pos -= line[cur-1]; printf("%d\n", getpos(cur, pos)); break; } else cur --; } } return 0; }
标签:
原文地址:http://www.cnblogs.com/LinKArftc/p/4902512.html