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. UIView的常用方法

    bringSubviewToFront: 把指定的子视图移动到顶层 - (void)bringSubviewToFront:(UIView *)view 参数 view 需要移到顶层的视图 conve ...

  2. VLD 1.0 ReadMe翻译尝试

    近期想学习下VLD的实现,打算从最简单的V1.0版本看起.以下是V1.0版本自己尝试翻译下,最新的2.x版本似乎强大了很多. 简介 Visual C++提供了内置的内存检测机制,但其充其量只满足了最小 ...

  3. 用ant重新编译jdk加入调试信息

    (文章后面提供了ant和build.xml打包之后的build.zip下载,解压build.zip,然后将apache-ant-1.9.2-bin.zip解压即完成了ant安装,也可到http://a ...

  4. phpexcel导入excel文件报the filename xxx is not recognised as an OLE file错误。

    工作中频繁会用phpexcel类导入excel文件的数据到数据库,目前常用的excel文件格式有:xls.csv.xlsx. 刚开始,针对xls文件,使用如下程序,能正常运行: $objReader ...

  5. org.quartz.impl.jdbcjobstore.LockException

    说明:在使用Tomcat6.0.32+Spring3.05+Quartz1.8.6+Mysql5.5.9 此项目在我本机上没有问题,当我把mysql 脚本导入到服务器上,将数据源配置修改为服务器对应的 ...

  6. Socket也有专门的Unicode版本

    https://www.chilkatsoft.com/refdoc/wcppCkSocketWRef.html https://www.chilkatsoft.com/refdoc/vcCkSock ...

  7. ant的入门 配置与安装

    最近需要用ant来生成文件,java类.我才开始了解了这个工具.仔细看了一下,感觉这个小工具的强大功能. 博主也是初学者,在网上收集了资料,尝试了配置:感觉有些高手写得不错变引用之. 配置如下: 以上 ...

  8. cf478C Table Decorations

    C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. 一、crond简介

    crond 是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务 工具,并且会自动启动crond进程,cro ...

  10. UIScollView Touch事件

    customScrollView.h #import <UIKit/UIKit.h> @interface customScrollView : UIScrollView @end cus ...