E - Number Sequence(第二季水)

时间:2021-10-13 08:07:32

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&lpar;第二季水)

    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 - 一只小蜜蜂&period;&period;&period;(第二季水)

    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. 如何在删除ibdata1和ib&lowbar;logfile的情况下恢复MySQL数据库

    昨天,有个朋友对公司内部使用的一个MySQL实例开启binlog,但是在启动的过程中失败了(他也没提,为何会失败),在启动失败后,他删除了ibdata1和ib_logfile,后来,能正常启动了,但所 ...

  2. 【BZOJ3282】Tree LCT

    1A爽,感觉又对指针重怀信心了呢= =,模板题,注意单点修改时splay就好,其实按吾本意是没写的也A了,不过应该加上能更好维护平衡性. ..还是得加上好= = #include <iostre ...

  3. ubuntu install wine

    1 install sUdo add-apt-repository ppa:wine/wine-builds sudo apt-get update sudo apt-get install wine ...

  4. eclipse中的web项目路径和发布好的项目路径

    现在企业开发中,我们都会创建一个javaWeb工程,在eclipse中指的是新建一个dynamic web project,创建完工程之后,我们在IDE中大体看到如下的工程目录: 我们主要关心的文件夹 ...

  5. UISearchDisplayController隐藏navigationBar需注意

    不能调用self.navigationController.navigationBar.hidden = YES: 调用此代码的话,你隐藏了navigationBar搜索展示控制器就拿不到导航条:就会 ...

  6. Codevs 2875 RY哥查字典

    时间限制: 1 s  空间限制: 16000 KB  题目等级 : 钻石 Diamond  题目描述 Description RY哥最近新买了一本字典,他十分高兴,因为这上面的单词都十分的和谐,他天天 ...

  7. asp&period;net mvc&plus;web api&plus;easyui

    前奏:第一次写博客,记录一下学习和开发的过程. 现在写的是一个后台管理系统,有基本的权限功能,其他功能都可以扩展.用到的技术是 asp.net mvc5,web api 2,entityframewo ...

  8. svg-写一个简单的进度条

    html <div class="container"> <div class="line-wrap"> <svg version ...

  9. 使用Google Cloud Platform构建机器学习项目-宠物识别

    宠物识别我们使用到了tensorflow object-detection API  (https://github.com/tensorflow/models/tree/master/researc ...

  10. Zabbix安装 Grafana安装

    每天学习一点点 编程PDF电子书免费下载: http://www.shitanlife.com/code 前提: 先需要安装好 lamp环境. 官方文档: https://www.zabbix.com ...