poj1019 Number Sequence
来源:互联网 发布:禁忌的边界线知乎 编辑:程序博客网 时间:2024/05/01 08:49
Number Sequence
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 34632 Accepted: 9949
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
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
283
Sample Output
22
Source
Tehran 2002, First Iran Nationwide Internet Programming Contest
题意:给你一串112123...这样的数列,然后让你求第n位的数字是多少。
做法:参考了人家大神的做法,首先知道后一窜数列比前一串数列多了log10(num)+1位,所以先预运算好,然后去找到n在那个数列中,找到之后就能做了。(更加详情的看代码。)
#include <iostream>#include <cstdio>#include <climits>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include<map>#include <algorithm>#include<ctime>#define esp 1e-6#define LL long long#define inf 0x0f0f0f0fusing namespace std;int main(){ long long a[50000]; long long s[50000],t,pos,ans; long long n,i,tt; a[1]=1; s[1]=1; for(i=2;i<=38000;i++) { a[i]=a[i-1]+(int)log10((double)i)+1; s[i]=s[i-1]+a[i]; } scanf("%lld",&tt); while(tt--) { scanf("%lld",&n); i=1; while(n>s[i]) { i++; } pos=n-s[i-1]; t=0; for(i=1;t<pos;i++) { t+=(int)log10((double)i)+1; } pos=t-pos; ans=(i-1)/(int)pow(10.0,(double)pos)%10; printf("%lld\n",ans); } return 0;}
0 0
- poj1019--Number Sequence题解
- POJ1019-Number Sequence
- POJ1019:Number Sequence
- POJ1019-Number Sequence
- POJ1019-Number Sequence
- POJ1019--Number Sequence
- poj1019 Number Sequence
- poj1019 Number Sequence
- poj1019 Number Sequence
- poj1019 Number Sequence
- POJ1019-Number Sequence
- POJ1019:Number Sequence
- 【poj1019】 Number Sequence
- poj1019 Number Sequence
- poj1019 递推 number sequence
- POJ1019:Number Sequence(组合计数)
- poj1019--Number Sequence(组合篇3)
- POJ1019————Number Sequence
- POJ 2540 Hotter Colder
- shell编程位置变量
- Motivated Word(3)
- C++BM算法
- TCC研究(2) 把C语言当作脚本,解释执行,并嵌入各类程序
- poj1019 Number Sequence
- 【BZOJ3209】花神的数论题 数位DP(我姿势不标准,但是可能更好写)
- The Third (构造函数,final )
- 远程触发SYSRQ获取最新的dmesg信息-一个几乎没有什么用的方案
- Spark源码走读4——Scheduler
- 007-读取游戏中的人物信息+输出调试信息 (郁金香老师 2015外挂教程)
- Sum It Up(HDU 1258)
- linux 交叉编译环境的搭建
- 008-人物信息数据的封装.基址与偏移管理单元库(郁金香灬老师 2015年游戏外挂视频教程第8课内容)