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

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

Source

Tehran 2002, First Iran Nationwide Internet Programming Contest
 
题意就不说了,看下就明白。思路就是打表,然后就是要知道求一个数的位数:(int)log10((double)x)+1
 
/*
ID: LinKArftc
PROG: 1019.cpp
LANG: C++
*/ #include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-8
#define randin srand((unsigned int)time(NULL))
#define input freopen("input.txt","r",stdin)
#define debug(s) cout << "s = " << s << endl;
#define outstars cout << "*************" << endl;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int INF = 0x7fffffff;
typedef long long ll; const int maxn = ; ll sum[maxn], line[maxn];//分别是前i行的位数和,第i行的位数 int getbit(int x) {
return (int)log10((double)x) + ;
} void init() {
sum[] = line[] = ;
for (int i = ; i <= ; i ++) {
line[i] = line[i-] + getbit(i);
sum[i] = sum[i-] + line[i];
}
} int getpos(int x, int pos) {
int len = getbit(x);
for (int i = ; i <= len - pos; i ++) x /= ;
return x % ;
} int main() { init();
int T;
ll n;
scanf("%d", &T);
while (T --) {
scanf("%lld", &n);
int cur = ;
while (sum[cur] < n) cur ++;
ll pos = n - sum[cur-];
while (cur >= ) {
if (pos > line[cur-]) {
pos -= line[cur-];
printf("%d\n", getpos(cur, pos));
break;
} else cur --;
}
} return ;
}
 
 

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. HDU 1005 Number Sequence

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

  3. POJ 1019 Number Sequence

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

  4. HDOJ 1711 Number Sequence

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

  5. Number Sequence

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

  6. [AX]AX2012 Number sequence framework :(三)再谈Number sequence

    AX2012的number sequence framework中引入了两个Scope和segment两个概念,它们的具体作用从下面序列的例子说起. 法国/中国的法律要求财务凭证的Journal nu ...

  7. KMP - HDU 1711 Number Sequence

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

  8. hdu 1005:Number Sequence(水题)

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

  9. Number Sequence 分类: HDU 2015-06-19 20:54 10人阅读 评论(0) 收藏

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

随机推荐

  1. restAssured + TestNG测试接口,以下是一个get 请求。

    package Elaine.Test.G.APITest; import org.testng.Assert;import org.testng.annotations.BeforeTest;imp ...

  2. Tomcat突然用开发工具启动不起来,只报了个红色的警告,没有其他任何异常

    碰到这个问题是,是因为我的catalina.bat文件做了配置修改,导致与工具这边的启动设置起了冲突 下面这个是我在Catalina.bat中新增的配置,删掉这个就可以了 set JAVA_OPTS= ...

  3. python3学习之路_day1

    登录程序1.输入用户名密码2.认证成功后显示欢迎信息3.输错三次后锁定 #!/usr/bin/env python #_*_coding:utf-8_*_ #by anthor gushiren 20 ...

  4. python 动态函数调用及可变参数传入

    定义类及方法 class ParameterFactory(object): ..... def fullLinkTag(self, fromDate, toDate, status, cate='全 ...

  5. remix无法安装的解决方案

    无法安装的原因: 因为remix依赖python 执行python又依赖c++的环境 所以连环导致出错 https://github.com/nodejs/node-gyp 措施一:降级处理 先清理缓 ...

  6. lintcode-98-链表排序

    98-链表排序 在 O(n log n) 时间复杂度和常数级的空间复杂度下给链表排序. 样例 给出 1->3->2->null,给它排序变成 1->2->3->nu ...

  7. js定时器实现图片轮播

    效果展示如下: setInterval(moverleft,3000);定时器设置为3秒,而且实现图片下方的小圆点序号跟图片对应,点击小圆点也能切换图片. 代码如下: <!DOCTYPE htm ...

  8. maven中如何得到父工程的位置

    目前的项目是一个父子工程项目,想要在子工程的pom文件中操作父工程目录下的资源. maven官方提供了标准的写法,比如parent.basedir之类的,网上可以找到很多,但尝试了之后就是不识别. 搞 ...

  9. ES mapping的写入与查看

    Elasticsearch索引mapping的写入.查看与修改 https://blog.csdn.net/napoay/article/details/52012249 首先创建一个索引: curl ...

  10. Thymeleaf 如何支持java8的时间LocalDate和LocalDatetime

    一.添加依赖 <dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thym ...