zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    bzoj2599
    在Linux下配置jdk的环境变量
    liunx 命令大全
    Liunx下如何使用kettle
    Liunx 解压篇
    Linux下安装MySQL-5.7
    Linux文件权限查看及修改命令chmod,chown
    spring 驱动模式
    Struts2标签之Checkbox
    spring 注解的优点缺点
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/5500640.html
Copyright © 2011-2022 走看看