题目链接:http://poj.org/problem?id=1019

题目大意:

  题目的意思很清楚了,就是把数字的每一位都当成是单个的字母来对待,然后求第i位的数是哪一个。(1<=i<=2^31-1)

题目分析:

  仔细观察并通过计算可以得知,想要通过穷举的方式用字符串来处理是行不通的,那就只好乖乖得着规律了。

  按照最大数字为1、2、3……的原则进行分组。发现了如下规律:

  一位数:

  1:1;

  12:2;

  ……

  123456789:9;

  两位数:

  12345678910:11;

  1234567891011:13;

  ……

  12345……99:189;

  最后发现到了五位数的某一位(大于31000,小于32000)时,总长度就已经超过2^31-1了。因而,数据并不算大,可以解决。按照上述规律,定义f[i]为i第一次出现的下标。

  那么就卡出i来,然后计算就可以了!

详细就看代码:

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
using namespace std;
#define MAX 2147483647
long long f[];//虽然MAX没有超过int但是所求之数是会超过的 void init()
{
f[]=;
int t=;
for(int i=;i<=;i++)
f[i]=f[i-]+i;
for(int i=;i<;i++)
f[i]=f[i-]+(t+=);
for(int i=;i<;i++)
f[i]=f[i-]+(t+=);
for(int i=;i<;i++)
f[i]=f[i-]+(t+=);
for(int i=;i<;i++)//这个上界很是重要!
f[i]=f[i-]+(t+=);
}
int main()
{
int t,n;
init();
cin>>t;
while(t--)
{
cin>>n;
if(n==)
{
cout<<<<endl;
continue;
}
for(int i=;i<;i++)
if(f[i-]<n&&f[i]>=n)
{
int temp=n-f[i-];//差值
if(temp>)//五位数
{
int t=temp-;
int t2=+(t-)/;
t-=*(t2-);
if(t==)
cout<<t2/<<endl;
if(t==)
cout<<(t2///)%<<endl;
if(t==)
cout<<(t2//)%<<endl;
if(t==)
cout<<(t2/)%<<endl;
if(t==)
cout<<t2%<<endl;
}else
if(temp>)//四位数
{
int t=temp-;
int t2=+(t-)/;
t-=*(t2-);
if(t==)
cout<<t2/<<endl;
if(t==)
cout<<(t2//)%<<endl;
if(t==)
cout<<(t2/)%<<endl;
if(t==)
cout<<t2%<<endl; }else
if(temp>)//三位数
{
int t=temp-;
int t2=+(t-)/;
t-=*(t2-);
//cout<<"t2="<<t2<<" t="<<t<<endl;
if(t==)
cout<<t2/<<endl;
if(t==)
cout<<(t2/)%<<endl;
if(t==)
cout<<t2%<<endl; }else
if(temp>)//二位数
{
int t=temp-;
int t2=+(t-)/;
t-=*(t2-);
if(t==)
cout<<t2/<<endl;
if(t==)
cout<<t2%<<endl;
}else
if(temp>)//一位数
cout<<temp<<endl;
break;
}
}
return ;
}

POJ1019

  

POJ1019-Number Sequence数学的更多相关文章

  1. POJ1019——Number Sequence(大数处理)

    Number Sequence DescriptionA single positive integer i is given. Write a program to find the digit l ...

  2. uva 10706 Number Sequence(数学规律)

    题目连接:10706 - Number Sequence 题目大意:有一个有0 ~ 9组成的序列,1   1 2    1 2 3   1 2 3 4   1 2 3 4 5 ....就是第一位为1. ...

  3. POJ1019 Number Sequence

    Number Sequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36256   Accepted: 10461 ...

  4. 1005:Number Sequence(hdu,数学规律题)

    Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1 ...

  5. 数学: HDU1005 Number Sequence

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. 杭电ACM刷题(2):1005,Number Sequence 标签: 杭电acmC语言 2017-05-11 22:43 116人阅读

    Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1 ...

  7. HDU 1005 Number Sequence

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  8. POJ 1019 Number Sequence

    找规律,先找属于第几个循环,再找属于第几个数的第几位...... Number Sequence Time Limit: 1000MS Memory Limit: 10000K Total Submi ...

  9. HDOJ 1711 Number Sequence

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  10. Number Sequence

    Number Sequence   A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) ...

随机推荐

  1. python终端中退格键,方向键不能使用

    在安装Python的时候先安装 yum install readline-devel.x86_64 -y 如果python已经安装过了就重新安装 ./configure    make all mak ...

  2. placeholder的字体样式改变,滚动条的颜色改变,ios日期兼容

    placeholder:::-webkit-input-placeholder { color: rgba(153, 153, 153, 0.541);font-size:12px;}:-moz-pl ...

  3. Azure Messaging-ServiceBus Messaging消息队列技术系列7-消息事务

    上篇博文中我们介绍了Azure Messaging-ServiceBus Messaging消息回执机制. Azure Messaging-ServiceBus Messaging消息回执机制 本文中 ...

  4. 关于ng-class的用法

    ng-class的使用几种方式 (1):利用双向数据绑定(className根据chang2的值去匹配类) <div class="{{className}}">... ...

  5. ecshop点滴记录

    会员中心: 用户中心页面的内容分布在两个模板文件中: user_clips.dwt(包含:欢迎页.我的留言.我的评论.我的标签.收藏商品.缺货登记.添加缺货登 记.我的推荐.单个商品推荐) user_ ...

  6. 老李分享:持续集成学好jenkins

    老李分享:持续集成学好jenkins   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.poptest测试开发工程师就业培训请大 ...

  7. Oracle常用数据字典

    1.查看所有存储过程.索引.表格.PACKAGE.PACKAGE BODY select * from user_objects; 2.查询所有的Job select * from user_jobs ...

  8. Selenium 2.0与Selenum 3.0介绍

    什么是Selenium Selenium是一组web自动化测试工具集,它由以下几个部分构成: Selenium IDE(Integrated Development Environment)这是Fir ...

  9. 请不要把‘通知的观察者注册’放在-viewWillAppear:中

    接手项目二次开发的吐槽: 接手别人的代码的悲哀之一就是,我反复的把流程走了一遍又一遍,却始终无法发现原来是这个问题. 之前这个人把通知的观察者注册放在了-viewWillAppear:中,导致,我发送 ...

  10. Android 接入 OpenCV库的三种方式

           OpenCV是一个基于BSD许可(开源)发行的跨平台计算机视觉库,可以运行在Linux.Windows.Android和Mac OS操作系统上.它轻量级而且高效——由一系列 C 函数和少 ...