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
第一次用二分法做出题来,太开心了,虽然这个简单;
#include <iostream>
#include <cmath>
using namespace std;
__int64 a[65540],i;
int main(){ int cmp(int,int,int);
a[0]=0;
for(i=1;i<65537;i++)
{
a[i]=a[i-1]+i;
}
__int64 b,c,n,m,k,j;
cin>>n;
while(n--){
cin>>m;
k=cmp(1,65535,m);
k=m-a[k-1];
k=k%9;
if(k)
cout<<k<<endl;
else cout<<"9"<<endl; } return 0;
}
int cmp(int d,int b,int c){
int mid=(d+b)/2;
if(d<=b)
{
if(c>a[mid-1]&&c<=a[mid])
return mid;
else if(c>a[mid]&&c<a[mid+1])
return mid+1;
else if(c>a[mid])
cmp(mid+1,b,c);
else cmp(d,mid-1,c);
} }

hdu1597的更多相关文章

  1. (lower_bound)find the nth digit hdu1597

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

  2. hdu-1597

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

  3. HDU1597【二分瞎搞】

    题意: 求第n个数: 思路: 可以看到一种序列: 1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567891 1234567891 ...

  4. OJ题目分类

    POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...

随机推荐

  1. Python代码一定要对齐

    不然会出现错误: IndentationError: unindent does not match any outer indentation level PS:新的Python语法,是不支持的代码 ...

  2. n!mod p的求法

    我们假设p为素数,n!=a*pe,则我们需要求解a mod p和e. e是n!能够迭代整除p的次数,因此可以使用下面式子计算: n/p+n/p2+n/p3…… 我们只需要对pt≤n的t进行计算所以复杂 ...

  3. hdu5322 Hope(dp)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Hope Time Limit: 10000/5000 MS (Java/Othe ...

  4. Window7下手动编译最新版的PCL库

    PCL简介 PCL是Point Cloud Library的缩写,是一个用于处理二维图像,三维深度图像和三维点云的C++库.该库是完全开源的,可免费用于商业和学术研究. 官方网站:http://poi ...

  5. freemarker中遍历list<map<String,String>>

    <#list var as map><tr> <#list map?keys as itemKey> //关键点    <#if itemKey=" ...

  6. Jquery 中 $('obj').attr('checked',true)失效的几种解决方案

    转载自:搜狐博客 大拙无为 1.$('obj').prop('checked',true) 2. $(':checkbox').each(function(){ this.checked=true; ...

  7. jquery.BannerRotator.js

    项目地址:https://github.com/snipertulip/BannerRotator 演示地址:http://snipertulip.github.io/BannerRotator/de ...

  8. 16-js-缓冲运动

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 畅通工程续--hdu1874

    畅通工程续 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  10. 能让汇编转到C51的初学者有更清晰的认识的一篇文章

    8051 是傳統 CISC 架構微控制器的代表,而 PIC 則是現代 RISC 架構微控制器的佳作. 雖然說 RISC 架構是公認未來微控制器的主流,但是 8051 藉著累積多年的發展環境與資源,特別 ...