poj1019

给定数列:1121231234...

求:某一位对应的数值

打表+二分

******************************

#include<cstdio>
#include<cstring>
#include<cmath>
#define MAXN 111111
#define P 31268
#define N 2147483647
using namespace std;

int a[10];
long long s[MAXN],sum[MAXN];

int cal(int x)
{
return (int)log10(x)+1;
}

void init()
{
int i=1;
long long cur=0;
while(cur<N)
{
s[i]=s[i-1]+cal(i);
cur=sum[i]=sum[i-1]+s[i];
i++;
}
}

int find(long long x)
{
int l=1,r=P;
while(l<=r)
{
int m=(l+r)>>1;
if(sum[m]>x)r=m-1;
else if(sum[m]==x)return m-1;
else l=m+1;
}
return l-1;
}

int find1(long long x)
{
int l=1,r=P;
while(l<=r)
{
int m=(l+r)>>1;
if(s[m]>x)r=m-1;
else if(s[m]==x)return m-1;
else l=m+1;
}
return l-1;
}

int main()
{
//freopen("in.txt","r",stdin);

init();

int t;
scanf("%d",&t);

while(t--)
{
long long n;
scanf("%lld",&n);

int p=find(n);
n-=sum[p];

p=find1(n);
n-=s[p];

p++;
int tot=0;
while(p)
{
a[++tot]=p%10;
p/=10;
}
int ans=a[tot+1-n];
printf("%d\n",ans);
}
return 0;
}


******************************

poj1019,布布扣,bubuko.com

时间: 2024-08-21 21:54:07

poj1019的相关文章

【poj1019】 Number Sequence

http://poj.org/problem?id=1019 (题目链接) 题意:给出一个数:1 12 123 1234 12345 123456 1234567 12345678 123456789 12345678910(当然中间是没有空格的)求它从左往右第n位上是多少. solution  水题一道.我们可以发现,这个数可以分成若干串数,记为i,那么每串数i就是从1~i.我们可以用数组x[i]来记录串i所占的空间也就是位数,数组sum[i]来记录串i的末尾位于整个串中的哪个位置.  对于每

POJ1019 NumberSequence 【数学公式转化题】

这题也是一看感觉自己能做,就拿出笔和纸开始写写画画了,写的也蛮爽(下午1点到晚上8点,,,),其实,,,也就俩方程的事情...但是中间出了个逗比错误,10+11+12+...+99算成了(1+90)*90/2(找出这个错误真心不容易,现学了点linuxshell知识,也正好写了写相关的脚本,比如对拍脚本,运行脚本,挺好的) 这个错误也是奇葩,,前7000个竟然都没错,,真是 奇葩- 感觉数学题还是要做慢点,尤其是写完一个重要的东西,检验一下,,,错了就毙掉了,很花时间,在代码量还算少的时候就调试

POJ1019——Number Sequence(大数处理)

Number Sequence DescriptionA single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consists of a sequence of positive integer numbers ranging from 1 t

poj1019 大数据处理 分块

Number Sequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33215   Accepted: 9490 Description A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...

POJ1019 Number Sequence

Number Sequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36256   Accepted: 10461 Description A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2..

poj1019(Number Sequence)

题目地址:Number Sequence 题目大意: 有一串序列由阿拉伯数字够成11212312341234512345612345671234567812345678912345678910123456789101112345678910.......然后问你第几位数字是什么输出该数字. 解题思路: 排列组合.假如算第79位数字为多少,先计算出它在那个1-n的区间,可以看出79在1-12这段数字的区间,然后计算出前面1.1-2.1-3....1-11所有数的总和有多少位减去之后,再通过模拟在1

acm常见算法及例题

转自:http://blog.csdn.net/hengjie2009/article/details/7540135 acm常见算法及例题 初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法

ACM算法总结及刷题参考

参考:http://bbs.byr.cn/#!article/ACM_ICPC/11777 OJ上的一些水题(可用来练手和增加自信)(poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094) 初期: 一.基本算法: (1)枚举. (poj1753,poj2965)    (2)贪心(poj1328,poj2109,poj2586)    (3)递归和分治法.     (4)递推.     (5)构造法.(po

POJ题目推荐(转载)

POJ推荐50题1.标记“难”和“稍难”的题目可以看看,思考一下,不做要求,当然有能力的同学可以直接切掉.2.标记为A and B的题目是比较相似的题目,建议大家两个一起做,可以对比总结,且二者算作一个题目.3.列表中大约有70个题目.大家选做其中的50道,且每类题目有最低数量限制.4.这里不少题目在BUPT ACM FTP上面都有代码,请大家合理利用资源.5.50个题目要求每个题目都要写总结,养成良好的习惯.6.这个列表的目的在于让大家对各个方面的算法有个了解,也许要求有些苛刻,教条,请大家谅