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. Qt Qwdget 汽车仪表知识点拆解7 图像绘制,旋转

    先贴上效果图,注意,没有写逻辑,都是乱动的 看下最中心的指针旋转,这里使用的QPainter的绘制函数 要显示复杂的效果,需要分层 void Widget::draw_number_pointer() ...

  2. 名片管理系统demo

    # 定义一个列表,用来储存名片 def cardInfors(): # 打印功能提示 print('欢迎使用名片管理系统v6.6.6') print('1:添加一个名片') print('2:删除一个 ...

  3. xamdin: 添加小组件报错: render() got an unexpected keyword argument 'renderer'

    查找到 xadmin里面的 dashboard.py文件内render方法,增加一个rdnderer默认参数是None一般路径在 本机虚拟环境\Lib\site-packages\xadmin\vie ...

  4. Halcon17对硬件配置要求

     Halcon17对硬件配置要求 Halcon17已经发布出来了,很多朋友一定想安装这款机器视觉软件来学习,我们今天给大家讲解下,Halcon17对硬件配置的要求: Halcon17 For Wind ...

  5. 用IIS防止mdb数据库被下载(转载)

    原网址:http://www.cnblogs.com/kingreatwill/p/4224433.html 第一种方法:要求网站管理人员具体asp编程经验.因为现在的销售虚拟主机的系统,已经为用户建 ...

  6. nodeJs 调试异步程序追踪异步报错

    DeprecationWarning: Calling an asynchronous function without callback is deprecated. 翻译: 不建议在不回调的情况下 ...

  7. Mac上基于hexo+GitHub搭建个人博客(一)

    原文地址: http://fanjiajia.cn/2018/11/23/Mac%E4%B8%8A%E5%9F%BA%E4%BA%8Ehexo+GitHub%E6%90%AD%E5%BB%BA%E4% ...

  8. lintcode-104-合并k个排序链表

    104-合并k个排序链表 合并k个排序链表,并且返回合并后的排序链表.尝试分析和描述其复杂度. 样例 给出3个排序链表[2->4->null,null,-1->null],返回 -1 ...

  9. hihocoder 后缀自动机专题

    一.后缀自动机基本概念的理解 1.首先后缀自动机的状态是由子串的endpos来决定的 子串的endpos是指一个子串可以在原字符串的哪些位置进行匹配, endpos构成的不同集合划分成不同的状态 关于 ...

  10. Netscaler GSLB的主备数据中心解决方案

    Netscaler GSLB的主备数据中心解决方案 http://blog.51cto.com/caojin/1898182 GSLB的主.备数据中心解决方案思路: 其实这只是多数据中心的一个特例而已 ...