题目描述 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…
cf1216E2 Numerical Sequence (hard version) 题目大意 一个无限长的数字序列,其组成为\(1 1 2 1 2 3 1.......1 2 ... n...\),即重复的\(1~1,1~2....1~n\),给你一个k,求第k(k<=1e18)个数字是什么 solution 暴力枚举妥妥T掉 手摸能看出来每一个单独的序列是等差数列 然后每一个序列的数字个数也是等差数列 如果预处理出等差数列的数组,那么询问的时候直接调用即可 参考lzz的blogs 说说这一段…
http://codeforces.com/problemset/problem/1216/E1 E1. Numerical Sequence (easy version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The only difference between the easy and the hard ver…
原题:poj3061 题意:给你一个数s,再给出一个数组,要求你从中选出m个连续的数,m越小越好,且这m个数之和不小于s 这是一个二分查找优化题,那么区间是什么呢?当然是从1到数组长度了.比如数组长度为10,你先找5,去枚举每一个区间为5的连续的数,发现存在这样的数,那么就可以继续往左找,反之则往右找,直到左右区间重合,即为正确答案,(有可能是右区间小于左区间,所以每次都应该求区间中点值) #include"iostream" #include"set" #incl…
题意:找到第一个出问题的版本 二分查找,注意 mid = l + (r - l + 1) / 2;因为整数会溢出 // Forward declaration of isBadVersion API. bool isBadVersion(int version); class Solution { public: int firstBadVersion(int n) { , r = n , ans ; while(l <= r){ ) / ; if(!isBadVersion(mid)){ l…
题目大意:求一个序列中不严格单调递增的子序列的最小数目(子序列之间没有交叉). 这题证明贪心法可行的时候,可以发现和求最长递减子序列的长度是同一个方法,只是思考的角度不同,具体证明并不是很清楚,这里就给出贪心法的解题过程. 首先很容易想到的就是对n长度数列进行n次遍历,每一次尽可能长地取出一个递增序列,显然这样最后取出的序列数目是最少的.但是这是一个n^2的算法,如果数据取极端的完全递减情况,很容易就能卡掉时间.Ps:这题的测试数据可能设计的并不是很严谨,这个简单的贪心法只要开一个记录已经取出序…
---恢复内容开始--- Description   Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so calledscribers. The scriber had been given a book and after several months he finished it…
Description Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate if you can find the three numbers Ai, Bj, Ck, which satisfy the formula Ai+Bj+Ck = X. Input There are many cases. Every data case is descr…
题目大意 有一个无限长的数字序列,其组成为1 1 2 1 2 3 1.......1 2 ... n...,即重复的1~1,1~2....1~n,给你一个\(k\),求第\(k(k<=10^{18})\)个数字是什么. 思路 设\(a[i]\)为该数到达\(i\)的长度,\(b[i]\)为第\(i\)个数那一块的长度,\(\sum b[i]=a[i]\),发现\([10^i,10^{i+1})\)的数长度均为\(i+1\),那么在这一段中\(b[i]\)都是一个等差数列,而计算\(a[i]\)就…
题目 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 fi…