Codeforces Round #352 (Div. 2) A.Summer Camp
2016-05-27 18:23
309 查看
A. Summer Camp
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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
output
input
output
题意:1234567891011....这样的一串序列,问你第几数字是多少?
思路:分个位,十位,百位进行讨论,个位时直接输出,十位数时,n小于190,ans=n-10,然后讨论ans如果是偶数则是十位的数,ans除以20再加1就是结果。如果ans是奇数,与20取模,除以2就是结果。百位数时,也是同样进行讨论即可。
总结:利用分类讨论的思想。
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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
题意:1234567891011....这样的一串序列,问你第几数字是多少?
思路:分个位,十位,百位进行讨论,个位时直接输出,十位数时,n小于190,ans=n-10,然后讨论ans如果是偶数则是十位的数,ans除以20再加1就是结果。如果ans是奇数,与20取模,除以2就是结果。百位数时,也是同样进行讨论即可。
#include <stdio.h> #include <iostream> using namespace std; int main() { int n; while(~scanf("%d",&n)) { if(n<=9) { printf("%d\n",n); continue; } if(n<=189) { int a=n-10; int b=a/20; int c=a%20; if(c%2==0) { printf("%d\n",b+1); continue; } if(c%2==1) { printf("%d\n",c/2); continue; } } if(n<=1000) { int a=n-190; int d=a/300; a=a-(d)*300; if(a%3==0) { printf("%d\n",d+1); continue; } int b=a/30; int c=a%30; if(a%3==1) { printf("%d\n",b); continue; } if(a%3==2) { printf("%d\n",c/3); continue; } } } }
总结:利用分类讨论的思想。
相关文章推荐
- LeetCode 349. Intersection of Two Arrays
- 面试题27:二叉搜索树按中序遍历原地转换为双向链表
- java 集合详解
- 数据库外键参数说明
- 利用KeyVault来加强存储Azure Storage访问密钥管理
- Java技术杂记
- fragment中嵌套fragment出现页面叠加、错乱
- 网站收集
- CodeForces 670B(模拟)水题
- h264数据通过RTP分片传输的例子
- 接口和抽象类的区别
- mysql innodb存储引擎和myisam引擎
- 本地运行hadoop-Failed to locate the winutils binary in the hadoop binary path-转载
- Android 4.4 Graphic系统详解(2) VSYNC的生成
- Map.containsKey方法——判断Map集合对象中是否包含指定的键名
- mybatis执行批量更新batch update 的方法(oracle,mysql)
- R语言之数据可视化
- tcp三次握手四次挥手原理(个人总结的特殊理解)
- 是春哥啊
- Apache jar包总结