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. 企业级Tomcat部署配置

    1.1 Tomcat简介 Tomcat是Apache软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache.Sun和其他一些公司及个人 ...

  2. pandas DataFrame行或列的删除方法

    pandas DataFrame的增删查改总结系列文章: pandas DaFrame的创建方法 pandas DataFrame的查询方法 pandas DataFrame行或列的删除方法 pand ...

  3. mingw编译opencv2.4.13问题记录

    为了在程序中用regex,升级了我的mingw,结果官网上的GCC版本都到6.3了,之前一直用4.8.换了编译器以后,对opencv2.4.10的引用就出了问题:undefined reference ...

  4. 二分图的最大匹配——Hopcroft-Karp算法

    http://blog.csdn.net/wall_f/article/details/8248373

  5. JavaSE复习(二)集合

    Collection List(存取有序,有索引,可以重复) ArrayList 底层是数组实现的,线程不安全,查找和修改快,增和删比较慢 LinkedList 底层是链表实现的,线程不安全,增和删比 ...

  6. C#故事

    C# 在腾讯的发展 <先定个小目标, 使用C# 开发的千万级应用> Xamarin 携程使用.Net技术 分布式高并发redis MQ dubbo kafka zookeeper

  7. SourceTree git的管理工具使用教程1

    1SourceTree是一个window系统下的Git管理工具 2设置Git 工具——选项——Git设置 3拷贝远程的项目 新建/克隆(输入远程项目的url地址) 4验证(填写用户信息) 工具——选项 ...

  8. 【转】深入理解Java中的String

    原文链接:http://www.cnblogs.com/xiaoxi/p/6036701.html 一.String类 想要了解一个类,最好的办法就是看这个类的实现源代码,来看一下String类的源码 ...

  9. [Java文件操作] 将素数输出到文件

    [要求]编写程序求出10万以内的所有素数,并将这些素数输出到一个文本文件中,每行文本只包含一个素数数据. import java.util.*; import java.io.*; public cl ...

  10. hdu6103 Kirinriki(trick+字符串)

    题解: 考虑一开始时,左边从1开始枚举,右边从n开始枚举 我们可以得到一个最大的值k. 但是如果这样依次枚举,复杂度肯定是n^3,是不行的 考虑如何利用上一次的结果,如果我们把1和n同时去掉 就可以利 ...