【HDU 1597】find the nth digit(模拟)
来源:互联网 发布:如何卸载软件管家 编辑:程序博客网 时间:2024/06/05 23:44
find the nth digit
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 12798 Accepted Submission(s): 3883
Problem Description
假设:
S1 = 1
S2 = 12
S3 = 123
S4 = 1234
.........
S9 = 123456789
S10 = 1234567891
S11 = 12345678912
............
S18 = 123456789123456789
..................
现在我们把所有的串连接起来
S = 1121231234.......123456789123456789112345678912.........
那么你能告诉我在S串中的第N个数字是多少吗?
S1 = 1
S2 = 12
S3 = 123
S4 = 1234
.........
S9 = 123456789
S10 = 1234567891
S11 = 12345678912
............
S18 = 123456789123456789
..................
现在我们把所有的串连接起来
S = 1121231234.......123456789123456789112345678912.........
那么你能告诉我在S串中的第N个数字是多少吗?
Input
输入首先是一个数字K,代表有K次询问。
接下来的K行每行有一个整数N(1 <= N < 2^31)。
接下来的K行每行有一个整数N(1 <= N < 2^31)。
Output
对于每个N,输出S中第N个对应的数字.
Sample Input
61234510
Sample Output
1
1
2
1
2
4
1
2
1
2
4
思路:把s写成数字塔,每层比上一层多一个,每层以9做循环,先判断在哪一层,再取模模拟就行了
#include<bits/stdc++.h>using namespace std;void solve(){ int k,n,i; scanf("%d",&k); while(k--){ scanf("%d",&n); int sum=0; for (i=1; sum<n; i++) sum+=i; sum-=i-1; n-=sum; if(n%9==0) printf("9\n"); else printf("%d\n",n%9); }}int main(){ solve(); return 0;}
0 0
- 【HDU 1597】find the nth digit(模拟)
- hdu 1597 find the nth digit(模拟)
- hdu Problem - 1597 find the nth digit
- HDU 1597 find the nth digit
- hdu 1597 find the nth digit
- Hdu 1597 find the nth digit
- hdu 1597 find the nth digit
- hdu 1597 find the nth digit
- HDU 1597 find the nth digit
- HDU 1597:find the nth digit
- hdu 1597 find the nth digit
- hdu find the nth digit(1597)
- hdu 1597 find the nth digit
- hdu 1597 数学题 find the nth digit
- HDU 1597 find the nth digit
- HDU 1597 find the nth digit
- HDU 1597 find the nth digit 水题
- HDU 1597:find the nth digit【规律】
- stack,deque,queue对比
- CSS3 媒介查询
- Python彻底解决采集网页乱码问题
- java守护线程和非守护线程
- 机器学习(周志华)习题解答-决策树(4.1-4.10)
- 【HDU 1597】find the nth digit(模拟)
- 【计算机视觉】人脸识别总结
- 蓝绿部署、A/B测试以及灰度发布
- VB利用PictureBox控件播放GIF动画
- unity官方教程Space shooter学习笔记-01
- 自己写GoBinarySearchTree 二叉查找树
- struct kobject
- L1-011. A-B
- 面向对象的六大原则