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. 个人博客作业-Week7

    团队任务中个人感想 我们团队选的题目是爬虫, 采用用AVA平台开发了, 我原来JAVA语言不熟悉了, PM考虑这部分之后分配任务这部分感觉很多谢 团队当中的PM很清楚每个组员的力量, 所以PM跟每个组 ...

  2. Java计算器(结对)

    一:题目简介 我们要做的是一个多功能计算器,Java程序编辑器是:图形界面.线程.流与文件等技术的综合应用. 图形界面的实现:考虑到简单.实用.高效等特点,就选择了Swing来完成实现,在选择组件上, ...

  3. Hibernate的初次使用

    使用hibernate的四个步骤:第一:创建一个hibernate.cfg.xml.<!DOCTYPE hibernate-configuration PUBLIC "-//Hiber ...

  4. (转)SqlDateTime 溢出。必须介于 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM之间

    原因: 出现这种问题多半是因为你插入或者更新数据库时,datetime字段值为空默认插入0001年01月01日造成datetime类型溢出. 传给数据库表的时间类型值是null值.这里的null指的是 ...

  5. 微信小程序动态数据跑马灯组件编写

    开发必备:熟悉微信小程序组件开发 开发思路:如果只有一条数据,直接用css3关键帧动画:如果有多条数据,则在当前动画运动到一定时间的时候,将其数据替换掉,使之在视觉效果上有一个从下到上播放的状态.数组 ...

  6. octave基本指令2

    octave基本指令2 数据移动 >> pwd %显示出当前路径 ans C:\Octave\3.2.4_gcc-4 >> cd 'G:\machine learning' % ...

  7. PAT 1028 人口普查

    https://pintia.cn/problem-sets/994805260223102976/problems/994805293282607104 某城镇进行人口普查,得到了全体居民的生日.现 ...

  8. 转《js闭包与内存泄漏》

    首先,能导致内存泄漏的一定是引用类型的变量,比如函数和其他自定义对象.而值类型的变量是不存在内存泄漏的,比如字符串.数字.布尔值等.因为值类型是靠复制来传递的,而引用类型是靠类似c语言中的指针来传递的 ...

  9. linux ubuntu nethogs安装与介绍

    安装nethogs: apt-get -y install ncurses* apt-get -y install libpcap-dev libncurses5-dev wget -c https: ...

  10. html 统一资源定位器(url)和url编码

    url,即统一资源定位器,也叫网址. 点击<a>标签就会连接到url指定的服务器web资源,文档或者其它数据: url的命名规则:url可是域名或者IP地址 url="shcem ...