find the nth digit

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 14416    Accepted Submission(s): 4444

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

Source

HDU 2007-Spring Programming Contest - Warm Up (1)

Recommend

8600

Statistic | Submit | Discuss | Note

#include<iostream>
#include<algorithm>
using namespace std;
long long a[];
int p[]={,,,,,,,,};
int main()
{
long long i;
a[]=;
for(i=;i<;i++)
a[i]=a[i-]+i;
long long n,t;
cin>>t;
while(t--)
{
cin>>n;
long long pos=lower_bound(a,a+,n)-a;
long long ans=n-a[pos-]; //ans指的是Sn中的第n行的数字的个数。
long long m=ans%; //这样会减少计算量。
cout<<p[m]<<endl;
}
return ;
}
lower_bound():找到大于等于某值第一次出现的迭代器位置。
upper_bound():找到大于某值第一次出现的迭代器位置。
equal_range():找到等于某值迭代器范围。
binary_search():在有序数列中确定给定元素是否存在。

(lower_bound)find the nth digit hdu1597的更多相关文章

  1. find the nth digit(二分查找)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1597 find the nth digit Time Limit: 1000/1000 MS (Jav ...

  2. 【LeetCode】400. Nth Digit 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  3. hdu 1597 find the nth digit

    find the nth digit Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  4. [Swift]LeetCode400. 第N个数字 | Nth Digit

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note:n is ...

  5. hdu 1597 find the nth digit (数学)

    find the nth digit Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  6. Martyr2项目实现——Number部分的问题求解 (1) Find Pi to Nth Digit

    Martyr2项目实现--Number部分的问题求解 (1) Find Pi to Nth Digit Find Pi to Nth Digit 问题描述: Find PI to the Nth Di ...

  7. [LeetCode] Nth Digit 第N位

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...

  8. Leetcode: Nth Digit

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...

  9. Nth Digit | leetcode

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...

随机推荐

  1. PAT甲题题解-1129. Recommendation System (25)-排序

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789819.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  2. 猫咪记单词Beta版使用说明

    猫咪记单词Beta版使用说明 一.项目背景 英语四级考试.六级考试.托福.雅思等英语方面的考试是现在大学生必须面对的问题.同时因为学生对手机的使用越来越频繁,而且仅仅通过书本背诵单词又比较无聊坚持的时 ...

  3. 转发:C#加密方法汇总

    转自:C#加密方法汇总 方法一: //须添加对System.Web的引用 using System.Web.Security; ... /// <summary> /// SHA1加密字符 ...

  4. json.dumps()和json.loads()

    json.dumps()用于将字典形式的数据转化为字符串,json.loads()用于将字符串形式的数据转化为字典,代码: import json data = { 'name' : 'Connor' ...

  5. Jmeter 常用断言使用

    响应断言 可根据要测试响应字段和模式匹配规则来设置断言,比如下方截图是匹配返回的结果中是否包含"code:200,",如果包含则表示断言成功,否则失败.响应断言可添加多个,但是多个 ...

  6. redi集群测试

    redis集群的测试   原文:http://blog.sina.com.cn/s/blog_53b45c4d0102wg10.html 1.测试存取值 客户端连接集群redis-cli需要带上 -c ...

  7. Cmder 常用配置

    windows 系统的 cmd 命令窗口不是很好用,可以试试 Cmder 工具包. 1.在运行框中快速启动 Cmder 将 cmder.exe 文件所在目录加载环境变量 PATH 中. 2.把 cms ...

  8. C/C++的内存泄漏检测工具Valgrind memcheck的使用经历

    Linux下的Valgrind真是利器啊(不知道Valgrind的请自觉查看参考文献(1)(2)),帮我找出了不少C++中的内存管理错误,前一阵子还在纠结为什么VS 2013下运行良好的程序到了Lin ...

  9. ubuntu 环境 celery配置全解

    继续尝试没有时间弄明白的技术. celery官方文档地址:http://docs.celeryproject.org/en/stable/getting-started/introduction.ht ...

  10. __new__ __init__区别

    1 class A(object): 2 def __init__(self,*args, **kwargs): 3 print "init A" 4 def __new__(cl ...