• Codeforces Round #352 (Div. 2) A. Summer Camp 水题


    A. Summer Camp

    Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.

    This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.

    Input

    The only line of the input contains a single integer n (1 ≤ n ≤ 1000) — the position of the digit you need to print.

    Output

    Print the n-th digit of the line.

    Examples
    input
    3
    output
    3
    input
    11
    output
    0
    Note

    In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.

    In the second sample, the digit at position 11 is '0', it belongs to the integer 10.

     题意 : 题目意思很简单。

     思路 : 由于n才1000,其实可以不断取余放到字符数组里,比赛时太想睡觉了…… 结果用了数学方法,思路不清晰写了20+min结果 stdtest还WA了...鶸orz

     1 #include <stdio.h>
     2 #include <iostream>
     3 #include <string.h>
     4 #include <algorithm>
     5 #define ll __int64
     6 using namespace std;
     7 
     8 const int INF = 0x3f3f3f3f;
     9 int main()
    10 {
    11     int n;
    12     cin >> n;
    13     if(n <= 9)
    14         printf("%d
    ", n);
    15     else if(n - 9 <= 180)
    16     {
    17         if((n-9)%2 == 1)
    18             printf("%d
    ", 1 + (n-9)/20);
    19         else
    20             printf("%d
    ",  (9+(n-9)/2)%10);
    21     }
    22     else
    23     {
    24         if((n-189)%3 == 1)
    25             printf("%d
    ", 1 + (n-189)/300);
    26         else if((n-189)%3 == 2)
    27             printf("%d
    ", (n-189)/30%10);
    28         else if((n-189)%3 == 0)
    29             printf("%d
    ", (99+(n-189)/3) %10);
    30     }
    31 
    32 }
  • 相关阅读:
    定制一个支持中英文的简单LaTex模板
    汉字hash问题(转)
    算法题之最大回文子串
    算法题之添加回文串
    数据表设计的步骤
    很简单的Java断点续传实现原理
    MongoDB 搭建文件存储的方案
    cron语法
    关于如何使用SVN的一些建议
    无后台应用 Stash Backend
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/5500640.html
Copyright © 2020-2023  润新知