二分
无敌大饺子
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
ZOJ 3090 Assemble(二分+贪心)
首先把所有的quality保存下来排序去重复.然后二分quality,对于每一个quality 选择每一类部件的quality大于等于这个quality的价格最小的部件.如果这个quality有部件不能达到这个quality或者有所有的最小价格的部件的总价大于预算就往左调quality(二分减小),否则可以往右调quality(二分增大).#include #include #in原创 2013-04-29 22:30:38 · 613 阅读 · 0 评论 -
ZOJ 2002 Copying Books(二分答案)
最大值最优化问题, 二分答案.每次二分的时候从后往前分配书即可满足条件.#include #include #include using namespace std;const int maxn = 510;long long P[maxn];bool Div[maxn], tmp[maxn];int N, K;int main(){ int nCase; scanf原创 2013-07-08 12:06:26 · 653 阅读 · 0 评论 -
LA 3177 Beijing Guards
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1178如果n是偶数,很显然最少需要最大的两个相邻士兵的要求礼物和.如果n是奇数,那就要二分答案了,对于p个礼物,第1个人需要r[1]个礼物,记为左边的礼物,剩下的p-r[1]个礼物记为原创 2013-06-01 16:49:16 · 833 阅读 · 0 评论 -
LA 2678 Subsequence
给出一个序列和一个数s 求出满足和大于等于s的最短子序列.做法如下:首先求出ss[i] 表示前i个数的和, 因为ss[i]是递增的,所以可以进行二分答案.#include #include using namespace std;const int maxn = 100010;int ss[maxn], sq[maxn], n, s;int main(){ while(~原创 2013-06-02 13:45:33 · 645 阅读 · 0 评论 -
SPOJ 1837 Pie
http://www.spoj.com/problems/PIE/一堆圆柱形的馅饼,一堆朋友,要求将这堆馅饼平等的分给这堆朋友(包括自己),馅饼可以被切成任何形状,但是只能是一块,求最大能分成的馅饼体积.思路:二分答案.#include #include using namespace std;const double PI = 3.1415926535898;cons原创 2013-05-31 17:44:11 · 1050 阅读 · 0 评论 -
HDU 4151The Special Number(暴力+二分)
首先枚举1 - 1000W的数字,把是special的数存在数组中,然后二分查找第一个大于n的数的位置.#include #include #include using namespace std;const int maxn = 1000000;int tb[maxn], n, idx;void init(){ for(int i = 1; i <= 10000000; +原创 2013-05-10 20:05:57 · 843 阅读 · 0 评论 -
ZOJ 2286 Sum of Divisors(打表)
可以用筛选法打表.然后对结果排序,再二分查找.#include #include #include #include #include using namespace std;const int maxn = 1000010;int tb[maxn], m;void init(){ int idx = 0; for (int i = 2; i <= 1000000;原创 2013-05-09 18:29:22 · 552 阅读 · 0 评论 -
SSU 154 Factorial(二分)
求最小的N满足N!尾部0的数量为q.直接用二分求了,注意0的情况,应该输出1.#include #include #include using namespace std;int q;int main(){ while (scanf("%d", &q) == 1){ long long n = LLONG_MAX; long long pre = n; long l原创 2013-05-05 18:39:51 · 601 阅读 · 0 评论 -
HDU 4190 Distributing Ballot Boxes(二分答案)
对最大人口进行二分.#include #include #include #include using namespace std;const int maxn = 500001;int pops[maxn] ,N, B;int main(){ while(scanf("%d%d", &N, &B)){ if(N == -1 && B == -1)break; int原创 2013-05-04 09:45:08 · 651 阅读 · 0 评论 -
ZOJ 1101 Gamblers
先对数组排序,再枚举+(二分或者map),O(n^3)*logn的复杂度.#include #include #include #include using namespace std;const int maxn = 1001;int wages[maxn], n;mapexist;bool bisearch(int x){ int l = 0, r = n - 1;原创 2013-05-17 22:03:49 · 531 阅读 · 0 评论 -
Codeforces 385C Bear and Prime Numbers(素数打表,二分)
题意:给出n个数,m次查询,每次查询一个区间[l,r],求n个数中是区间[l,r]之间素数倍数的个数和,每个素数都要算一次和.解法:由于Xi最大为10^7,所以可以开一个这么大的数组,用筛选法求出素数和对应的和,最后查询的时候二分找素数位置.#include #include #include using namespace std;const int MAX = 10000001原创 2014-04-07 10:24:28 · 1496 阅读 · 0 评论
分享