[CodeForces]-672A-Summer Camp
2016-08-10 22:13
351 查看
[CodeForces]-672A-Summer Camp
原题:
A - Summer Camp
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
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.
Sample Input
Input
3
Output
3
Input
11
Output
0
Hint
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.
题目大意:就是在123456789101112…这样一个按顺序的数列中,给出下标,然后得到对应的数。
题目分析:这种题一般就直接找规律就可以了。所以可以暴力一点,开个数组打表就可以了。我们可以发现我们要找的坐标的极限是1000这样,所以对应的数估计是400左右,我们把999跑出来就可以了
代码:
原题:
A - Summer Camp
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
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.
Sample Input
Input
3
Output
3
Input
11
Output
0
Hint
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.
题目大意:就是在123456789101112…这样一个按顺序的数列中,给出下标,然后得到对应的数。
题目分析:这种题一般就直接找规律就可以了。所以可以暴力一点,开个数组打表就可以了。我们可以发现我们要找的坐标的极限是1000这样,所以对应的数估计是400左右,我们把999跑出来就可以了
代码:
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> using namespace std ; const int max_n = 20000 + 10 ; int a[max_n] ; int main() { int count = 0 ; for(int i = 1 ; i <= 999 ; i++) { if(i>=1&&i<=9){ a[++count] = i ; } else if(i>=10 &&i <= 99){ int shi = i/10 ; int ge = i %10 ; a[++count] = shi ; a[++count] = ge ; } else if(i>=100 &&i <=999){ int bai = i/100; int shi = (i%100)/10 ; int ge = i %10 ; a[++count] = bai ; a[++count] = shi ; a[++count] = ge ; } } int n ; cin>>n ; cout<<a ; return 0 ; }
相关文章推荐
- 【HDU 5366】The mook jong 详解
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces 407C Codeforces Round #239 (Div. 1)C
- 【水题】跑跑卡丁车系列之游戏下载
- HDU 5240 Exam (好水的题)
- 【2016 Multi-University Training Contest 1】【hdu5723】Abandoned Countries
- 【WHUST 2016 Individual Contest #1】解题报告
- 【WHUST 2016 Individual Contest #2】解题报告
- 【WHUST 2016 Individual Contest #3 】解题报告
- 【2016 Multi-University Training Contest 6】【1002】【A Simple Chess】
- CodeForces 449A - Jzzhu and Chocolate
- CodeForces 449 B. Jzzhu and Cities
- codeforces 618C. Constellation
- 北大—1006——Biorhythms
- Codeforces Round #349 (Div. 2) - C
- Codeforces Round #361 (Div. 2)
- hdu 6011
- codeforces 768E Game of Stones