UVa 10427-naughty Sleepy Boys

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.