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 ...
随机推荐
- C语言解析日志,存储数据到伯克利DB 2
#编译程序 gcc -o historydb historydb.c -ldb #将2013年8月9日的用户记录写入数据库 (程序自动识别新用户入库,跳过老用户) ./historydb -f .us ...
- qemu cow镜像分析
最近研究了以下qemu最简单的read on direct 镜像格式cow,在稀疏文件的模式下,这种方式还是比较简单,而且有优势的.其优势主要体现在云计算环境中,不需要用到qcow2的那些诸如内部快照 ...
- discuz@功能的代码
//转载 $atlist = $atlist_tmp = $ateduids = array(); preg_match_all("/@([^\r\n]*?)\s/i", $mes ...
- BZOJ 1565 植物大战僵尸
http://www.lydsy.com/JudgeOnline/problem.php?id=1565 思路:由于植物之间有保护关系:(右边的植物保护左边的植物,植物攻击范围内的植物都被保护了),因 ...
- LeetCode_Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 〔写在OS边上〕定性note
转载:http://tieba.baidu.com/p/1273477757 0 neta 有的时候我们在读书或者看文档.——啊,原来这东西的框架就是这样而已,很直白么.有的时候我们在读代码.——于是 ...
- mysqli connect database and print
<?php $connect = mysqli_connect('localhost','root','','intertrading') or die('Unale to connect'); ...
- c++ 友元类
一.友元类相关概念 要将私有成员数据或函数暴露给另一个类,必须将后者声明为友元类. 注意三点: (1)友元关系不能传递 (2)友元关系不能继承 (3)友元关系不能互通
- hdu 5248 序列变换(二分枚举)
Problem Description 给定序列A={A1,A2,...,An}, 要求改变序列A中的某些元素,形成一个严格单调的序列B(严格单调的定义为:Bi<Bi+,≤i<N). 我们 ...
- js实现a标签超链接提交form表单的方法
<a class="regButton" id="saveRegister" onclick="document.getElementBy ...