(lower_bound)find the nth digit hdu1597
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的更多相关文章
- find the nth digit(二分查找)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1597 find the nth digit Time Limit: 1000/1000 MS (Jav ...
- 【LeetCode】400. Nth Digit 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- hdu 1597 find the nth digit
find the nth digit Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- [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 ...
- hdu 1597 find the nth digit (数学)
find the nth digit Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 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 ...
- [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 ...
- 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 ...
- 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 ...
随机推荐
- 对wordcount单词字母部分的修改
原始代码: int s; s = ch; switch (s) { case 'a':letter[0]++; break; case 'b':letter[1]++; break; case 'c' ...
- Daily Scrumming* 2015.12.22(Day 14)
一.团队scrum meeting照片 二.成员工作总结 姓名 任务ID 迁入记录 江昊 任务1112 无 任务说明 今天没有写前端界面,而是完成了跨域请求的实现以及用户实名认证API 前后端大部分数 ...
- 【课程总结】Linux内核分析课程总结
程涵 原创博客 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 每周实验报告: 反汇编一个简单的C程序 ...
- Filter学习:项目第八阶段
public interface Filter A filter is an object that performs filtering tasks on either the request ...
- hg命令
hg常用命令 hg命令跟git命令大同小异 hg version 查看hg版本 hg clone url 克隆代码仓库 hg branch newBranch 创建分支 hg update other ...
- PAT 1049 数列的片段和
https://pintia.cn/problem-sets/994805260223102976/problems/994805275792359424 给定一个正数数列,我们可以从中截取任意的连续 ...
- 【转】XSHELL下直接下载文件到本地(Windows)
XSHELL下直接下载文件到本地(Windows) http://www.cnblogs.com/davytitan/p/3966606.html
- Redis应用一例(存证数量用计数器实现)
public Long getCreationCounter() { String host =PropertyUtils.getPropertyValue("redis.server.ho ...
- PLSQL 使用ODBC 数据源导入来自SQLSERVER的数据
1. 创建ODBC数据源 方法: 打开控制命令 Win10 运行->输入 control 查看方式大图标--选择 管理工具 2. 安装了 64位的plsql 应该也选用 64位的ODBC数据源 ...
- CMake--Set用法
CMake中的set用于给一般变量,缓存变量,环境变量赋值. cmake官方文档set set(<variable> <value> [[CACHE <type> ...