Numerical Sequence (easy version)
http://codeforces.com/problemset/problem/1216/E1
2 seconds
256 megabytes
standard input
standard output
The only difference between the easy and the hard versions is the maximum value of k
.
You are given an infinite sequence of form "112123123412345…
" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from 1 to 1, the second one — from 1 to 2, the third one — from 1 to 3, …, the i-th block consists of all numbers from 1 to i
.
So the first 56
elements of the sequence are "11212312341234512345612345671234567812345678912345678910". Elements of the sequence are numbered from one. For example, the 1-st element of the sequence is 1, the 3-rd element of the sequence is 2, the 20-th element of the sequence is 5, the 38-th element is 2, the 56-th element of the sequence is 0
.
Your task is to answer q
independent queries. In the i-th query you are given one integer ki. Calculate the digit at the position ki
of the sequence.
The first line of the input contains one integer q
(1≤q≤500
) — the number of queries.
The i
-th of the following q lines contains one integer ki (1≤ki≤109)
— the description of the corresponding query.
Print q
lines. In the i-th line print one digit xi (0≤xi≤9) — the answer to the query i, i.e. xi should be equal to the element at the position ki
of the sequence.
5
1
3
20
38
56
1
2
5
2
0
4
2132
506
999999999
1000000000
8
2
9
8
Answers on queries from the first example are described in the problem statement.
题意:在数列中查找第i个数是多少。
//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdio.h>
#include <queue>
#include <stack>;
#include <map>
#include <set>
#include <string.h>
#include <sstream>
#include <vector>
#define ME(x , y) memset(x , y , sizeof(x))
#define SF(n) scanf("%d" , &n)
#define rep(i , n) for(int i = 0 ; i < n ; i ++)
#define INF 0x3f3f3f3f
#define mod 1000000007
#define PI acos(-1)
using namespace std;
typedef long long ll ;
int l[];
int c[];
int s[]; int length(int x)
{
if(x >= )
{
return ;
}
else if(x >= )
{
return ;
}
else if(x >= )
return ;
else if(x >= )
return ;
else
return ;
} void init()
{
for(int i = ; i <= ; i++)
{
l[i] = length(i);
c[i] = c[i-]+l[i];
s[i] = s[i-]+c[i];
}
} int main()
{
int t ;
init();
scanf("%d" , &t);
while(t--)
{
int n;
scanf("%d" , &n);
int index = lower_bound(s+ , s+ , n) - s;
n -= s[index-];
index = lower_bound(c+ , c+index , n) - c;
n -= c[index-] ;
n = l[index] - n ;
while(n--)
{
index /= ;
}
printf("%d\n" , index%);
} return ;
}
Numerical Sequence (easy version)的更多相关文章
- cf1216E2 Numerical Sequence (hard version)(思维)
cf1216E2 Numerical Sequence (hard version) 题目大意 一个无限长的数字序列,其组成为\(1 1 2 1 2 3 1.......1 2 ... n...\), ...
- [CF1216E] Numerical Sequence hard version
题目 The only difference between the easy and the hard versions is the maximum value of k. You are giv ...
- cf1216E2 Numerical Sequence (hard version) 二分查找、思维题
题目描述 The only difference between the easy and the hard versions is the maximum value of k. You are g ...
- 【二分】CF Round #587 (Div. 3)E2 Numerical Sequence (hard version)
题目大意 有一个无限长的数字序列,其组成为1 1 2 1 2 3 1.......1 2 ... n...,即重复的1~1,1~2....1~n,给你一个\(k\),求第\(k(k<=10^{1 ...
- CF1264D1 Beautiful Bracket Sequence (easy version)
考虑在一个确定的括号序列中,我们可以枚举中间位置,按左右最长延伸出去的答案计算. 我们很自然的思考,我们直接维护左右两边,在删除一些字符后能够延伸的最长长度. 我们设\(f_{i,j}\)为\(i\) ...
- Ping-Pong (Easy Version)(DFS)
B. Ping-Pong (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input ...
- CF1225B1 TV Subscriptions (Easy Version)
CF1225B1 TV Subscriptions (Easy Version) 洛谷评测传送门 题目描述 The only difference between easy and hard vers ...
- ZOJ 3868 - Earthstone: Easy Version
3868 - Earthstone: Easy Version Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld ...
- Codeforces 1077F1 Pictures with Kittens (easy version)(DP)
题目链接:Pictures with Kittens (easy version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:$dp[i][j ...
随机推荐
- Apache HttpClient 读取响应乱码问题总结
Apache HttpClient 读取响应乱码问题总结 setCharacterEncoding Content-Type HttpClient 起因 最近公司产品线研发人员调整,集中兵力做战 ...
- H5 FileReader对象
前言:FileReader是一种异步文件读取机制,结合input:file可以很方便的读取本地文件. input:file 在介绍FileReader之前,先简单介绍input的file类型. < ...
- 【leetcode】523. Continuous Subarray Sum
题目如下: 解题思路:本题需要用到这么一个数学定理.对于任意三个整数a,b,k(k !=0),如果 a%k = b%k,那么(a-b)%k = 0.利用这个定理,我们可以对数组从头开始进行求和,同时利 ...
- jquery-时间轴滑动
效果预览图: html: <div class="tim"> <div class="timdiv"> <div class=&q ...
- python list 插入元素
https://www.jb51.net/article/57923.htm List 是 Python 中常用的数据类型,它一个有序集合,即其中的元素始终保持着初始时的定义的顺序(除非你对它们进行排 ...
- 一、Nginx常见问题
1.相同server_name多个虚拟主机优先级访问 最先读取哪个配置文件,就访问那个的网页 2.location匹配优先级 相同location,会被后面的覆盖 匹配优先级更高的,找后面的 = ...
- 洛谷P1077 摆花——题解
题目传送 题目大意:有按顺序放的n种花,相同种类的花放一起,每种花最多放ai盆,共放了m盆花,求放花方案数. 求方案个数一般有以下思路:1.搜索:2.递推/动态规划:3.贪心:4.分治... 玄学估计 ...
- AT2370 Piling Up
https://www.luogu.org/jump/atcoder/2370 题解 答案不是\(2^{2m}\)因为每轮的第一次取球可能会不够. 我们可以设\(dp[i][j]\)表示到了第\(i\ ...
- [思路题][LOJ2290][THUWC2017]随机二分图:状压DP+期望DP
分析 考虑状压DP,令\(f[sta]\)表示已匹配状态是\(sta\)(\(0\)代表已匹配)时完美匹配的期望数量,显然\(f[0]=1\). 一条边出现了不代表它一定在完美匹配内,这也导致很难去直 ...
- [BZOJ3236]:[Ahoi2013]作业(莫队+分块)
题目传送门 题目描述 此时已是凌晨两点,刚刚做了$Codeforces$的小$A$掏出了英语试卷.英语作业其实不算多,一个小时刚好可以做完.然后是一个小时可与做完的数学作业,接下来是分别都是一个小时可 ...