HDU1597 find the nth digit
find the nth digit
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 16138 Accepted Submission(s): 5108
Problem Description
假设:
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)。
Output
对于每个N,输出S中第N个对应的数字.
Sample Input
6 1 2 3 4 5 10
Sample Output
1 1 2 1 2 4
Author
8600
解题思路
若要找到N所对应的数,需要先找到在第几个串里面,这个其实很好找,依次递减就能找到。有两种情况:如果刚好剪成0,说明在减去最后一个数的那个穿的最后一个数,反之就在下一个串里面,对9取模就得到答案了。
AC代码
#include<iostream>
using namespace std;
int m[]={9,1,2,3,4,5,6,7,8};
int main()
{ int t;cin>>t;while(t--) { long long a;cin>>a;int i=1;while(a>=i)a-=i++;if(a==0) cout<<m[(i-1)%9]<<endl;else cout<<m[a%9]<<endl;}return 0;
}
HDU1597 find the nth digit相关推荐
- HDU1597 find the nth digit【模拟】
find the nth digit Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu1597 find the nth digit(二分查找)
find the nth digit Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 2141 Can you find it? hdu1597 find the nth digit
hdu2141 唉,是我 想多了,用普通方法拼命剪枝,还是TLE 直接将前俩个数组的和求出来并保存,之后就是一个二分查找的过程了 二分的俩种写法 第一种 #include<iostream> ...
- C#LeetCode刷题之#400-第N个数字(Nth Digit)
问题 在无限的整数序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...中找到第 n 个数字. 注意:n 是正数且在32为整形范围内 ( n < 231). 输入:3 ...
- 杭电1597 find the nth digit
find the nth digit Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 1597 find the nth digit(等差求和+二分)
find the nth digit Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- LeetCode算法题-Nth Digit(Java实现)
这是悦乐书的第215次更新,第228篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第83题(顺位题号是400).找到无限整数序列的第n个数字1,2,3,4,5,6,7,8 ...
- LeetCode Nth Digit
题意:给出一个正整数n<2^31-1,求序列中1,2,3,4,...,的第n个数是多少.如果n=10,第10个数是0 思路:用两个数组f和init,数组f[i]表示位数为i的数的个数,init[ ...
- 杭电1597_find the nth digit
Problem Description 假设: S1 = 1 S2 = 12 S3 = 123 S4 = 1234 ......... S9 = 123456789 S10 = 12345678 ...
最新文章
- 页面与ViewModel(上)
- 【Android】入门级连接网络示例: 网页浏览和播放网络MP3
- uses 子句的写法
- 遍历XML引擎版本以适应代码
- C#对象映射器之Mapster
- docker卸载 windows版本_DevOps系列 006 - Docker安装
- windows qt 使用openssl API
- JS中去除字符串空格trim()函数
- 6U VPX 电源产品学习资料第411篇:基于6U VPX的700W/1400W 电源产品
- 如何使用ShoeBox和PhotoShop制作出漂亮的Fnt字体
- [2014年10月5日亲测可用]迅雷极速版高速通道加速破解补丁发布
- 如何快速去掉word页眉横线
- 带你走进Choerodon猪齿鱼的知识管理
- 最新县及县以上行政区划代码(截止2016年7月31日)
- 什么是 Holdout Set?
- 生成固定的句子,句子中含有给定的多个关键词,python代码实现
- 2014.03.31_一年很快过去了
- 【完美解决】应用程序无法正常启动(0xc000007b)请单击“确定”关闭应用程序
- CSS之标签选择器、ID选择器、类选择器
- 基于SSH框架的二手物品交易网(Struts)