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...Sk. Each group Sk consists of a sequence of positive integer numbers ranging from 1 to k, written one after another.         For example, the first 80 digits of the sequence are as follows:         11212312341234512345612345671234567812345678912345678910123456789101112345678910

Input

The first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by one line for each test case. The line for a test case contains the single integer i (1 ≤ i ≤ 2147483647)      

Output

There should be one output line per test case containing the digit located in the position i.      

Sample Input

2
8
3

Sample Output

2
2 这道题不打表会超时 ,以下 超时代码
#include<iostream>
#include<cmath>
using namespace std;
void f(int n)
{
int p=,j=,t;
bool flag;
while(){
flag=false;
for(j=;j<=p;j++){
int i;
for(i=;;i++){
t=pow((double),i);
if(j/t==){
n-=i;
break;
}
}
if(n<=){
int k=i+n;
flag=true;
n=j%(int)(pow((double),i-k+))/pow((double),i-k);
break;
}
}
if(flag==true)break;
p++;
}
cout<<n<<endl;
}
int main()
{
int t;
cin>>t;
while(t--){
int n;
cin>>n;
f(n);
}
//system("pause");
return ;
}

打表后!!!这个代码不好理解

#include<iostream>
#include<cmath>
using namespace std;
unsigned int a[],s[];
void f()
{
int i;
a[]=;
s[]=;
for(i=;i<;i++)
{
a[i]=a[i-]+(int)log10((double)i)+; //记录1至s[i]个数字的位数和
s[i]=s[i-]+a[i]; //一位 记录 1至s[i]个数字
}
}
int main()
{
int t;
int n;
int i;
cin>>t;
f();
while(t--)
{
cin>>n;
i=;
while(s[i]<n) i++;
int pos=n-s[i-];
int tmp=;
for(i=;tmp<pos;i++) //第n个数字在s[i-1]这个数据组中
{
tmp+=(int)log10((double)i)+;
}
int k=tmp-pos; //数字i从低位数的第k+1位
cout<<(i-)/(int)pow(10.0,k)%<<endl;
}
return ;
}

E - Number Sequence(第二季水)的更多相关文章

  1. F - The Fun Number System(第二季水)

    Description In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight o ...

  2. D - Counterfeit Dollar(第二季水)

    Description Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are t ...

  3. I - Long Distance Racing(第二季水)

    Description Bessie is training for her next race by running on a path that includes hills so that sh ...

  4. Y - Design T-Shirt(第二季水)

    Description Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA ...

  5. N - Robot Motion(第二季水)

    Description A robot has been programmed to follow the instructions in its path. Instructions for the ...

  6. B - Maya Calendar(第二季水)

    Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old ...

  7. S - 骨牌铺方格(第二季水)

    Description          在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.         例如n=3时,为2× 3方格,骨牌的铺放方案有三种, ...

  8. R - 一只小蜜蜂...(第二季水)

    Description          有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数.         其中,蜂房的结构如下所示.     ...

  9. G - Reduced ID Numbers(第二季水)

    Description T. Chur teaches various groups of students at university U. Every U-student has a unique ...

随机推荐

  1. 安装SQL2008时遇到"未能加载文件或"file:///d:microsoft..sql.chainer.packagedata.dll"或它的某个依赖项

    安装SQL2008时遇到"未能加载文件或"file:///d:microsoft..sql.chainer.packagedata.dll"或它的某个依赖项,如下图所示 ...

  2. HttpURLConnection详解

    HttpURLConnection详解 07. 五 / J2EE / 没有评论   HttpURLConnection类的作用是通过HTTP协议向服务器发送请求,并可以获取服务器发回的数据. Http ...

  3. 火狐浏览器,hostadmin hosts文件访问权限不足

    开始->附件->以管理员身份运行. cacls %windir%\system32\drivers\etc\hosts /E /G Users:W

  4. 记录一下C#+Oracle批量插入的一个方法

    public bool insertOracle(DataTable dataTable, string sql) // Oracle sql 查询的是表头 { string ConnStr = Wi ...

  5. python之3内置容器

    所谓内置容器,就是不需要第三方模块,就可以使用的. 1.list容器,一个有序序列,类似于数组,但比数组强大很多 1.1.如何初始化list,直接一个[]即可,这是一个空的list >>& ...

  6. nginx之如何获取真实客户端ip

    nginx的配置文件中日志格式加入$http_x_forwarded_for--> log_format access '$remote_addr - $remote_user [$time_l ...

  7. 1010 Area

    题目要求面积和判断非相邻边不相交.和数学和几何有关系. #include <stdio.h> #include <math.h> #define MISS 0.0000001 ...

  8. psutil官方文档

    psutil documentation¶ Quick links Home page Install Blog Forum Download Development guide What’s new ...

  9. 理解 backbone.js 中的 bind 和 bindAll 方法,关于如何在方法中指定其中的 this,包含apply方法的说明[转载]

    转载自:http://gxxsite.com/content/view/id/132.html 在backbone.js的学习过程中,被bind和bindAll弄得有点晕,这里包括underscore ...

  10. Extjs4 Grid内容已经拿到但是不显示数据

    原先照着Extjs4.0.7官方文档写了一个GridPanel的列子,没有什么问题,今天又自己写了一个,效果如下,内容肯定拿到就是不显示: 经过一段代码排查后,问题出在了自定义Model时将field ...