poj 1019 Number Sequence 第i位上的数字 (组合数学)
来源:互联网 发布:编程笔记本电脑 编辑:程序博客网 时间:2024/06/08 05:14
Number Sequence
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 37699 Accepted: 10890
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
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>#include<climits>using namespace std;#define all(x) (x).begin(), (x).end()#define for0(a, n) for (int (a) = 0; (a) < (n); (a)++)#define for1(a, n) for (int (a) = 1; (a) <= (n); (a)++)#define len(x) ( log10(x*1.0)+1 )typedef long long ll;typedef pair<int, int> pii;const int INF =0x3f3f3f3f;const int maxn= 31268 ;int a[maxn+10];void pre(){ for(int i=1;i<=maxn+1;i++) { a[i]=a[i-1]+len(i); }}int work(ll x){ ll s=0;int p; for(int i=0;i<=maxn;i++)//从0开始 { s+=a[i]; if(s+a[i+1]>=x) { p=i; break; } } ll leave=x-s; s=0; for(int i=1;i<=p+1;i++) { s+=len(i); if(s>=leave) { p=i; break; } } return p/(int)( pow(10.0,1.0*s-leave)+0.5)%10;}int main(){ pre(); ll x; int T;scanf("%d",&T); while(T--) { scanf("%lld",&x); printf("%d\n",work(x)); } return 0;}
0 0
- poj 1019 Number Sequence 第i位上的数字 (组合数学)
- POJ 1019 Number Sequence (数学+预处理 循环递增序列第k位数字)
- POJ 1019 Number Sequence(组合数学)
- poj 1019 Number Sequence (组合数学)
- POJ-1019-Number Sequence-组合数学
- POJ 1019Number Sequence(组合数学)
- 组合数学 POJ 1019 Number Sequence
- poj 1019 Number Sequence 数学
- Number Sequence--组合数学
- (DS1.5.10)POJ 1019 Number Sequence(确定一个数字序列中某一个位置上的数字)
- poj 1019 Number Sequence 数学&模拟
- [poj 1019] Number Sequence 数学 想法题
- poj 1019Number Sequence(数学 巧妙~~~)
- POj 1019 number sequence(数学)
- (hdu1005)Number Sequence(组合数学)
- POJ 1019 Number Sequence
- POJ 1019 Number Sequence
- poj 1019 Number Sequence
- Unity使用OpenCvSharp人脸识别
- POJ1051
- 【Leetcode】Palindrome Partitioning
- a 与&a 的区别
- window.onscroll无效问题
- poj 1019 Number Sequence 第i位上的数字 (组合数学)
- datatables 查询功能代码备份
- HTTP的GET和POST格式解析
- 电路交换和分组交换
- 排序
- JavaScript-设计模式之接口的实现
- iOS支付宝支付
- Unicode编码区间
- HDOJ 1342 DFS