hdu1597
S1 = 1
S2 = 12
S3 = 123
S4 = 1234
.........
S9 = 123456789
S10 = 1234567891
S11 = 12345678912
............
S18 = 123456789123456789
..................
现在我们把所有的串连接起来
S = 1121231234.......123456789123456789112345678912.........
那么你能告诉我在S串中的第N个数字是多少吗?
接下来的K行每行有一个整数N(1 <= N < 2^31)。
6
1
2
3
4
5
10
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的更多相关文章
- (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 ...
- hdu-1597
find the nth digit Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU1597【二分瞎搞】
题意: 求第n个数: 思路: 可以看到一种序列: 1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567891 1234567891 ...
- OJ题目分类
POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...
随机推荐
- poj3122 binary search 实数区间
Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14536 Accepted: 4979 Special Ju ...
- ZigZag-LeetCode
题目: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows l ...
- Linux上安装JDK
1.下载rpm文件并安装 rpm -ivh jdk-7u51-linux-x64.rpm 2.修改/etc/profile文件,增加以下配置 export JAVA_HOME=/usr/java/jd ...
- chart.js 示例
一个简单的例子. 1.html代码 <div id="pie" style="width: 250px;float:left"> <h3> ...
- 用委托、匿名函数、Lambda的方式输出符合要求的数
最近看了一些博客,对委托和匿名函数和Lambda的方式有了一些更深的理解,在前人的基础上.我也写3个例子 using System; using System.Collections.Generic; ...
- No enclosing instance of type test8 is accessible. Must qualify the allocation with an enclosing instance of type test8 (e.g. x.new A() where x is an
在编译一个例子时,结果编译时出现: No enclosing instance of type test8 is accessible. Must qualify the allocation wit ...
- 10个经典的Android开源项目(附源码包)
最近在抽空学习Android系统开发,对Android学习也比较感兴趣,刚开始学就试着在网上找几个项目源码研究看下,以下就将找到的Android项目源码列出,希望对正在或准备学习Android系统开发 ...
- 在C中嵌入汇编
早前公布了C和汇编混编的温度控制器程序,收到一些朋友的询问,他们无法在自己程序中使用我的18B20的汇编子程序或无法正常通过混编后的程序编译. 其实在KEIL中嵌入汇编的方法很简单.如图一,在C文件中 ...
- Static, Shared Dynamic and Loadable Linux Libraries
转载:http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html Why libraries are used: Th ...
- java.lang.OutOfMemoryError: GC overhead limit exceeded 问题分析和解决(转)
在项目历史数据导入过程中,出现了应用无法访问的情况.立刻对Weblogic进行分析,发现Weblogic的内存.线程等性能良好,Server也是Running的状态.随后查看了Weblogic日志,在 ...