随笔分类 -  二分&&三分

摘要:题目传送门 1 /* 2 二分:搜索距离,判断时距离小于d的石头拿掉 3 */ 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 10 typedef long long ll;11 const... 阅读全文
posted @ 2015-07-25 18:46 Running_Time 阅读(136) 评论(0) 推荐(0)
摘要:题目传送门 1 /* 2 题意:分成m个集合,使最大的集合值(求和)最小 3 二分搜索:二分集合大小,判断能否有m个集合。 4 */ 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 11... 阅读全文
posted @ 2015-07-25 18:43 Running_Time 阅读(135) 评论(0) 推荐(0)
摘要:题目传送门 1 /* 2 题意:n条绳子问切割k条长度相等的最长长度 3 二分搜索:搜索长度,判断能否有k条长度相等的绳子 4 */ 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 11... 阅读全文
posted @ 2015-07-25 18:38 Running_Time 阅读(118) 评论(0) 推荐(0)
摘要:题目传送门 1 /* 2 三分:凹(凸)函数求极值 3 */ 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 10 const int MAXN = 1e4 + 10;11 const int ... 阅读全文
posted @ 2015-07-25 18:27 Running_Time 阅读(133) 评论(0) 推荐(0)
摘要:题目传送门 1 /* 2 二分搜索:式子两边取对数,将x提出来,那么另一边就是一个常数了,函数是:lnx/x。二分搜索x,注意要两次 3 */ 4 #include 5 #include 6 #include 7 using namespace std; 8 9 const dou... 阅读全文
posted @ 2015-07-25 18:23 Running_Time 阅读(192) 评论(0) 推荐(0)
摘要:题目传送门 1 /* 2 二分搜索:枚举高度,计算体积与给出的比较。 3 */ 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 10 const int MAXN = 1e3 + 10;11 ... 阅读全文
posted @ 2015-07-25 18:16 Running_Time 阅读(182) 评论(0) 推荐(0)
摘要:题目传送门 1 /* 2 题意:给出一个数,问是否有ai + bj + ck == x 3 二分查找:首先计算sum[l] = a[i] + b[j],对于q,枚举ck,查找是否有sum + ck == x 4 */ 5 #include 6 #include 7 #incl... 阅读全文
posted @ 2015-07-25 18:12 Running_Time 阅读(175) 评论(0) 推荐(0)
摘要:题目传送门 1 /* 2 题意:一个汉堡制作由字符串得出,自己有一些原材料,还有钱可以去商店购买原材料,问最多能做几个汉堡 3 二分:二分汉堡个数,判断此时所花费的钱是否在规定以内 4 */ 5 #include 6 #include 7 #include 8 using na... 阅读全文
posted @ 2015-07-25 18:07 Running_Time 阅读(250) 评论(0) 推荐(0)
摘要:题目传送门 1 /* 2 题意:问有几个区间最大值-最小值 8 #include 9 #include 10 #include 11 using namespace std;12 13 typedef long long ll;14 const int MAXN = 1e5 + 10;1... 阅读全文
posted @ 2015-07-22 12:23 Running_Time 阅读(256) 评论(0) 推荐(0)
摘要:二分专题int p=lower_bound(A,A+n,x)-A; //查询>=x的第一个下标int p=upper_bound(A,A+n,x)-A; //查询>x的第一个下标int p=upper_bound(A,A+n,x)-A-1; //查... 阅读全文
posted @ 2015-07-19 13:28 Running_Time 阅读(197) 评论(0) 推荐(0)
摘要:题目传送门 题意:问区间内x的出现的次数分析:莫队算法:用一个cnt记录x的次数就可以了。还有二分查找的方法代码:#include #include #include #include using namespace std;const int MAXN = 1e5 + 10;const int I... 阅读全文
posted @ 2015-07-16 08:29 Running_Time 阅读(243) 评论(0) 推荐(0)
摘要:题目传送门 1 /* 2 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 3 */ 4 #include 5 #include 6 #include 7 using namespace std; 8 9 cons... 阅读全文
posted @ 2015-06-09 15:11 Running_Time 阅读(235) 评论(0) 推荐(0)
摘要:题目传送门 1 /* 2 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找。贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 3 当然有可能两个数和超过p,那么an的值最优,每次还要和an比较 4 注意:不能选取两个... 阅读全文
posted @ 2015-06-08 10:23 Running_Time 阅读(158) 评论(0) 推荐(0)
摘要:题目传送门 1 /* 2 题意:给定一个数列,求最大的r使得[l,r]的数字能在t次全变为0,每一次可以在m的长度内减1 3 二分搜索:搜索r,求出sum 7 #include 8 #include 9 #include 10 using namespace std;11 12... 阅读全文
posted @ 2015-06-02 17:42 Running_Time 阅读(137) 评论(0) 推荐(0)
摘要:题目传送门 1 /* 2 二分搜索:在0~1e6的范围找到最小的max (ai - bi),也就是使得p + 1 6 #include 7 #include 8 #include 9 #include 10 using namespace std;11 12 const int MA... 阅读全文
posted @ 2015-05-31 10:21 Running_Time 阅读(224) 评论(0) 推荐(0)
摘要:题目传送门 1 /* 2 二分找到不大于m的最大的数,记做p,只要a[p] + k 6 #include 7 #include 8 #include 9 using namespace std;10 11 typedef long long ll;12 13 const int MA... 阅读全文
posted @ 2015-05-31 10:14 Running_Time 阅读(170) 评论(0) 推荐(0)
摘要:题目传送门 1 /* 2 题意:查询x的id,每次前排的树倒下 3 使用lower_bound ()查找高度,f[i]记录第一棵高度为x树的位置,查询后+1(因为有序) 4 */ 5 #include 6 #include 7 #include 8 using namespac... 阅读全文
posted @ 2015-05-27 21:46 Running_Time 阅读(163) 评论(0) 推荐(0)
摘要:题目传送门 1 /* 2 题意:问值为x的个数有几个,第二次查询就是0 3 lower/upper_bound ()函数的使用,map也可过,hash方法不会 4 */ 5 #include 6 #include 7 #include 8 #include 9 #includ... 阅读全文
posted @ 2015-05-27 21:32 Running_Time 阅读(140) 评论(0) 推荐(0)