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 ...
随机推荐
- javascript的DOM操作(二)
<html> <title>学习DOM</title> <a id="wen">文本</a> <input nam ...
- hprof教程
大部分内容参考http://www.linuxidc.com/Linux/2012-04/58178.htm J2SE中提供了一个简单的命令行工具来对java程序的cpu和heap进行 profili ...
- C# winform 窗体 彻底退出窗体的方法
1.this.Close(); 只是关闭当前窗口,若不是主窗体的话,是无法退出程序的,另外若有托管线程(非主线程),也无法干净地退出: 2.Application.Exit(); 强制所有消 ...
- .net mvc结合微软提供的FormsAuthenticationTicket登陆
一.Web.config <system.web> <compilation debug="true" targetFramework="4.5&quo ...
- LeetCode_Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- Powershell变量的类型和强类型
Powershell变量的类型和强类型12 12月, 2011 在 Powershell tagged Powershell教程 / 变量 / 存储 / 数据 / 类型 by Mooser Lee ...
- sort详解
一. 简介 sort命令是帮我们依据不同的数据类型进行排序. 二. 语法 sort [-bcfMnrtk][源文件][-o 输出文件] 补充说明:sort可针对文本文件的内容,以行为单位来排序(默认为 ...
- hdu 1853 最小费用流好题 环的问题
Cyclic Tour Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/65535 K (Java/Others) Tota ...
- UML--核心元素之用例
Use case 一个系统就是由各种各样的愿望组成的. 一个用例就是与参与者actor交互的,并且给参与者提供可观测的有意义的结果的一系列活动的集合. 例如你想做一顿饭吃,你需要完成煮饭和炒菜两件事情 ...
- impala编译
impala编译 编译系统centos 5.10 说明:版本1.3.x----2.1.x都能编译 一.预装库 1.gcc安装 yum install gcc44 yum install gcc44-c ...