Title: Starting from 1 consecutive integers make up a string, and ask Nth which is the corresponding character of the bit.
Analysis: Dynamic programming, DP. Count the length of the preceding substring corresponding to each number;
Find the substring of the corresponding string of the given length, and then take the character of the N-len (substring) corresponding to the number.
Description: Refueling ╮(╯▽╰)╭.
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace Std;long long Sum[20000002];char temp[10];char *itoc (int i) {int t = I,cou NT = 0;while (t) {count ++;t = T/10;} Temp[count--] = 0;while (i) {temp[count--] = i%10 + ' 0 '; I/= 10;} return temp;} int BS (int key) {int L = 0,r = 20000000;while (L < r) {int mid = (l+r+1)/2;if (Sum[mid] >= key) r = Mid-1;else L = mid ;} return l;} int main () {sum[0] = 0ll;int add = 1;for (int i = 1; i < 20000001; + + i) {if (i = =) (i = =) | | i = = | | | i = = 1 0000 | | i = = 100000 | | i = = 1000000 | | i = = 10000000) Add ++;sum[i] = Sum[i-1]+add;} int N,m;while (~SCANF ("%d", &n)) {m = BS (n);p rintf ("%c\n", Itoc (m+1) [n-sum[m]-1]);} return 0;}
UVa 10427-naughty Sleepy Boys