![](https://img-blog.csdnimg.cn/20190927151101105.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
二分
二分
River_____________
这个作者很懒,什么都没留下…
展开
-
4 Values whose Sum is 0 POJ - 2785(二分查找)
题意:给出四列数,要求从每一列中选择一个使得最终四个数的和为0,求有多少种情况。 分析:直接枚举的复杂度是O(n^4) 明显TL ,用二分进行简化的话是O(n^2) 。首先枚举前两列的和,然后再从后两列中查找和为前两列和的结果就可以了,因为在后两列中可能会在相同列中会出现相同的数,排完序后用upper_bound和lower_bound可以轻松求出(这样又简化了时间)。 收获:原创 2017-03-08 23:50:48 · 268 阅读 · 0 评论 -
从有序数组中查找某个值(二分)
#include #include using namespace std; const int maxn = 10000; int a[maxn]; int n,k; void solve() { int lb=-1,ub=n; while(ub-lb>1) { int mid=(lb+ub)/2; if(a[mid]>=k)原创 2017-03-13 18:47:06 · 399 阅读 · 0 评论 -
F - Dropping tests POJ - 2976(二分)
F - Dropping tests POJ - 2976(二分) In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be . Given your test scores原创 2017-03-13 21:23:58 · 246 阅读 · 0 评论 -
C - Anton and Fairy Tale CodeForces - 785C(经典二分)
其实还可以找总结规律来做,但是不太会以后做了再补上。 对于这道题而言,二分的上限确定错了,导致wa了无数发。 对于n 对于n>m的情况只有当 天数k开始大于m时,第k天结束到第k+1天晚上之前粮仓才不会是满的,并且从第k天开始,每天会减少的会+1,那么在粮仓变空的第x天,粮仓一共减少的就是1+2+3+4........(直接等差数列求和) ,当我们求出的和的值大于等于n-m(因为从第m天开始原创 2017-04-10 17:01:27 · 337 阅读 · 0 评论 -
POJ3977(折半枚举)
原来一直以为的map.lowerbound和upperbound是错的。。。 学习了make_pair #include #include #include #include #include using namespace std; typedef long long LL; const int maxn = 1000000+10; map M; int n; LL s[m原创 2017-06-26 19:09:54 · 347 阅读 · 0 评论