poj1019 很好的一道数学题 思路挺巧
2014-06-26 13:06
393 查看
借鉴别人的思路,利用位数求解:思路不错。
题意:求第n位的数字。
函数log10((double)i)+1,求的是一个数的位数。
当达到31270时,已经超过了2147483647位数
#include<iostream>
#include<cstdio>
#include<cmath>
#define max 31270
using namespace std;
unsigned int a[max];
unsigned int s[max];
void start()
{
int i,j;
a[1]=1;
s[1]=1;
for(i=2; i<31270; i++) //打表记录总的位数
{
a[i]=a[i-1]+(int)log10((double)i)+1;
s[i]=s[i-1]+a[i];
}
}
int res(int n)//预处理,不断缩小范围
{
int i=1,j=1;
int m=0;
int len=0;
for(i=1; i<31270; i++)
{
if(s[i]>=n)
break;
}
int pos=n-s[i-1];
for(j=1; len<pos; j++)
{
len+=(int)log10((double)j)+1;
}
return ((j-1)/(int)pow(10.0,len-pos))%10;
}
int main()
{
int t;
int test;
cin>>t;
start();
while(t--)
{
cin>>test;
cout<<res(test)<<endl;
}
return 0;
}
http://blog.sina.com.cn/s/blog_13127b7010101qfaz.html
http://whbqstar385.blog.163.com/blog/static/236990017201452044843862/
http://www.douban.com/note/360911049/
http://bbs.tianya.cn/post-1008-183448-1.shtml
http://bbs.tianya.cn/post-1035-26701-1.shtml
http://beijing.qd8.com.cn/yiyao/xinxi21_5145937.html
http://blog.sina.com.cn/s/blog_13127b7010101qfn9.html
http://whbqstar385.blog.163.com/blog/static/236990017201452111858717/
http://www.douban.com/note/361163399/
http://bbs.tianya.cn/post-1008-183496-1.shtml
http://bbs.tianya.cn/post-1035-26702-1.shtml
http://beijing.liebiao.com/yiliao/121177706.html
http://www.k518.com/beijing/zhuankeyiyuan/a9969906.html
http://blog.sina.com.cn/s/blog_13127b7010101qgrh.html
http://whbqstar385.blog.163.com/blog/static/23699001720145234837517/
http://www.douban.com/note/361790598/
http://bbs.tianya.cn/post-1008-183752-1.shtml
http://bbs.tianya.cn/post-1035-26714-1.shtml
http://www.k518.com/beijing/yiyuan/a10000755.html
http://beijing.liebiao.com/yiliao/122021859.html
http://blog.sina.com.cn/s/blog_13127b7010101qher.html
http://whbqstar385.blog.163.com/blog/static/23699001720145244332854/
http://www.douban.com/note/362167200/
http://bbs.tianya.cn/post-1008-183914-1.shtml
http://bbs.tianya.cn/post-1035-26772-1.shtml
http://bbs.plu.cn/thread-5221470-1-1.html
http://beijing.liebiao.com/yiliao/122413426.html
http://www.k518.com/beijing/yiyuan/a10021993.html
http://blog.sina.com.cn/s/blog_13127b7010101qhy5.html
http://whbqstar385.blog.163.com/blog/static/23699001720145254343073/
http://www.douban.com/note/363317701/
http://bbs.tianya.cn/post-1008-184006-1.shtml
http://bbs.iiyi.com/thread-2496804-1.html
http://bbs.tianya.cn/post-1035-26816-1.shtml
http://club.health.sohu.com/man/thread/2fiim271iho
http://beijing.liebiao.com/yiliao/122818580.html
题意:求第n位的数字。
函数log10((double)i)+1,求的是一个数的位数。
当达到31270时,已经超过了2147483647位数
#include<iostream>
#include<cstdio>
#include<cmath>
#define max 31270
using namespace std;
unsigned int a[max];
unsigned int s[max];
void start()
{
int i,j;
a[1]=1;
s[1]=1;
for(i=2; i<31270; i++) //打表记录总的位数
{
a[i]=a[i-1]+(int)log10((double)i)+1;
s[i]=s[i-1]+a[i];
}
}
int res(int n)//预处理,不断缩小范围
{
int i=1,j=1;
int m=0;
int len=0;
for(i=1; i<31270; i++)
{
if(s[i]>=n)
break;
}
int pos=n-s[i-1];
for(j=1; len<pos; j++)
{
len+=(int)log10((double)j)+1;
}
return ((j-1)/(int)pow(10.0,len-pos))%10;
}
int main()
{
int t;
int test;
cin>>t;
start();
while(t--)
{
cin>>test;
cout<<res(test)<<endl;
}
return 0;
}
http://blog.sina.com.cn/s/blog_13127b7010101qfaz.html
http://whbqstar385.blog.163.com/blog/static/236990017201452044843862/
http://www.douban.com/note/360911049/
http://bbs.tianya.cn/post-1008-183448-1.shtml
http://bbs.tianya.cn/post-1035-26701-1.shtml
http://beijing.qd8.com.cn/yiyao/xinxi21_5145937.html
http://blog.sina.com.cn/s/blog_13127b7010101qfn9.html
http://whbqstar385.blog.163.com/blog/static/236990017201452111858717/
http://www.douban.com/note/361163399/
http://bbs.tianya.cn/post-1008-183496-1.shtml
http://bbs.tianya.cn/post-1035-26702-1.shtml
http://beijing.liebiao.com/yiliao/121177706.html
http://www.k518.com/beijing/zhuankeyiyuan/a9969906.html
http://blog.sina.com.cn/s/blog_13127b7010101qgrh.html
http://whbqstar385.blog.163.com/blog/static/23699001720145234837517/
http://www.douban.com/note/361790598/
http://bbs.tianya.cn/post-1008-183752-1.shtml
http://bbs.tianya.cn/post-1035-26714-1.shtml
http://www.k518.com/beijing/yiyuan/a10000755.html
http://beijing.liebiao.com/yiliao/122021859.html
http://blog.sina.com.cn/s/blog_13127b7010101qher.html
http://whbqstar385.blog.163.com/blog/static/23699001720145244332854/
http://www.douban.com/note/362167200/
http://bbs.tianya.cn/post-1008-183914-1.shtml
http://bbs.tianya.cn/post-1035-26772-1.shtml
http://bbs.plu.cn/thread-5221470-1-1.html
http://beijing.liebiao.com/yiliao/122413426.html
http://www.k518.com/beijing/yiyuan/a10021993.html
http://blog.sina.com.cn/s/blog_13127b7010101qhy5.html
http://whbqstar385.blog.163.com/blog/static/23699001720145254343073/
http://www.douban.com/note/363317701/
http://bbs.tianya.cn/post-1008-184006-1.shtml
http://bbs.iiyi.com/thread-2496804-1.html
http://bbs.tianya.cn/post-1035-26816-1.shtml
http://club.health.sohu.com/man/thread/2fiim271iho
http://beijing.liebiao.com/yiliao/122818580.html
相关文章推荐
- POJ-Crazy tea party,很好的一道数学题~~~
- poj1019 很好的一道数学题 思路挺巧
- POJ 1019 数学找规律
- poj1019 Number Sequence 二分+数学+打表
- poj1019(数学)
- POJ1019 NumberSequence 【数学公式转化题】
- poj1019——Number Sequence(数学)
- [poj 1019] Number Sequence 数学 想法题
- poj 1019 Number Sequence 数学
- POJ 1019 模拟思路题 化整为零
- poj 3414 Pots(认为是一道很好的bfs题目)
- poj 1019 Number Sequence (组合数学)
- POJ 1019 Number Sequence(组合数学)
- poj 1125 Stockbroker Grapevine 很好的一道floyd入门题
- POJ 1019 Number Sequence (数学+预处理 循环递增序列第k位数字)
- POJ 1019 许久之前,觉得这真是一道神题呢。。 递推+二分
- POJ-1019-Number Sequence-组合数学
- poj 1019(数学题)
- POJ-1019 Number Sequence 数学
- POJ-1019-数学规律