CodeForces 483B 二分答案】的更多相关文章

题目: B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have two friends. You want to present each of them several positive integers. You want to present cnt1 number…
n people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed. You can put a bomb in some point with non-n…
上学期刷过裸的RMQ模板题,不过那时候一直不理解>_< 其实RMQ很简单: 设f[i][j]表示从i开始的,长度为2^j的一段元素中的最小值or最大值 那么f[i][j]=min/max{d[i][j-1], d[i+2^j-1][j-1]} RMQ的ST算法: void ST() //初始化 { memset(RMQ,,sizeof(RMQ)); ;i<=n;i++) RMQ[i][]=a[i]; ;(<<j)<=n;j++) ;i+(<<j)-<=…
大意: 平面上n个点每个点坐标为(x,0)或(0,y), 求任意两点距离平方最大值的最小值. 二分答案, 转化为判定最大值是否<=e, 按$x$排序后, 因为固定左端点, $y$绝对值的最大值是跟右端点单调的, 滑动一个长度平方不超过e的区间, 同时保证右端点$x$的绝对值不超过左端点, 这样对于左端点在$x$轴的情况一定是最优的, 同样再固定右端点倒序处理正半轴的情况. #include <iostream> #include <random> #include <a…
题面 传送门 分析 二分答案,考虑如何判定 可以用贪心的方法,每次找最快没电的电脑,在没电前1单位时间给它充电 正确性显然 实现上可以维护一个堆,存储每个电脑电用完的时刻,每次从堆顶取出最小的一个给它充电.设二分值为mid,对于每个电脑记录它的充电次数num[i],则没电的时间就是\(\lfloor \frac{a_i+num_i\times mid}{b_i} \rfloor+1\) 如果在维护堆的过程中发现当前时间已经超过某个电脑的没电时间,则返回false 时间复杂度\(O(n\log n…
参考了这个博客哇 #include<cstdio> #include<algorithm> #include<cstring> #define Max(a,b,c,d) max(max(a,b),max(c,d)) #define Min(a,b,c,d) min(min(a,b),min(c,d)) using namespace std; double a,b,c,d,l,r=1000000000,mid; bool check(double lim) { doub…
题意:给你n个数,将他们分成连续的三个部分使得每个部分的和相同,求出分法的种数. 思路:用一个数组a[i]记下从第一个点到当前i点的总和.最后一个点是总和为sum的点,只需求出总和为1/3sum的点和总和为2/3sum的点搭配的所有情况.遍历一遍总和为2/3sum的点前总和为1/3sum的点的个数. #include<stdio.h> #include<string.h> #include<iostream> using namespace std; ; typedef…
[题目链接] http://codeforces.com/problemset/problem/700/A [题目大意] 有一辆限载k人速度为v2的车,n个步行速度均为v1的人要通过一段长度为l的距离,每个人只能上车一次,车可以来回走,问所有人到达目的地所需要的最短时间是多少 [题解] 因为车可以载k个人,所以,我们把人k个为一组分成(n+k-1)/k组,记为p吗,设需要的最短时间为t,每个人在车上待的时间为t2,那么可以列方程v1*(t-t2)+v2*t2=l,我们可以发现t2可以用t来表示,…
链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: 思路: 因为查询的到的值一定是输入的其中一个,那么我们可以二分答案,判断二分得到的答案是否符合,那么在这里我们就只需要找到某个数x,查询区间[l,r]有多少个连续的数大于x,这个操作只需要将高度从小到达排序,倒着插入主席树中,值设为1,那么只要维护有多少个连续的1(线段树区间合并的方法),就代表有…
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebo…