
二分法
芋智波佐助
菜鸟一只
展开
-
UVa 2678 Subsequence / 二分
求长度最短的连续序列 它的和大于等于s 输出长度枚举起点和终点会超时求出前缀和 都是正整数 所以前缀和是递增的如果对于前缀和 sum[i]要使得长度最小 那么应该找出最大的j 使得 sum[i]-sum[j]>=s sum[j] #include #include #include using namespace std;const int maxn = 1000原创 2014-01-23 23:11:42 · 1153 阅读 · 0 评论 -
CF 479D Long Jumps
#include #include #include #include using namespace std;int a[100010];int n;bool find(int x){ int l = 0, r = n-1; while(l <= r) { int m = (l+r) >> 1; if(a[m] == x) return true; i原创 2014-11-06 15:45:59 · 941 阅读 · 0 评论 -
HDU 3081 Marriage Match II 二分+最大流
题目来源:HDU 3081 Marriage Match II题意:思路: 错误代码 纠结不知道哪错了 先放一放 #include #include #include #include #include using namespace std;const int maxn = 1010;const int INF = 999999999;struct Edg原创 2014-05-08 17:46:58 · 892 阅读 · 0 评论 -
UVa 11865 Stream My Contest 二分+最小树形图
题目来源:UVa 11865 Stream My Contest 题意:0是服务器 其他每个点要接收到0传送的数据 并且每条路单向 有最大带宽和花费 求总花费不超过c的最大带宽思路:单向的0是根 是一颗有向树 要最大化带宽 是树中所有边最小的带宽尽量大 然后总得花费不超过n 二分最小带宽 然后选出带宽大雨二分mid值的边 判断是否存在最小树形图 存在说明mid值可行 此外没有用到白书上原创 2014-06-01 14:26:02 · 1070 阅读 · 0 评论 -
HDU 2962 Trucking 最短路+二分
题目来源 HDU 2962 题意:给你一张无向图n个点m条边 给出起点s终点e和最大承受的高度 其中每条路都有限制的高度以及该条路的长度 求从s到e最大可以通过的高度和在最大高度的前提下的最短路思路:二分高度再求最短路 无解特判一下#include #include #include #include using namespace std;const int maxn原创 2014-04-04 23:16:25 · 905 阅读 · 0 评论 -
HDU 1839 Delay Constrained Maximum Capacity Path 最短路+二分
题目来源:HDU 1839 Delay Constrained Maximum Capacity Path题意:给你一张无向图 要从1到n运送东西 每条路都有容量限制和经过的时间 选择一条路径该路径最多能运的数量等于容量最少的那条边 并且总时间不能超过T思路:和上一题一样 二分容量 然后做最短路判断是否最短时间小于等于T#include #include #include #in原创 2014-04-04 23:40:59 · 1041 阅读 · 0 评论 -
POJ 2976 Dropping tests 01分数规划 二分解法
01分数规划:令a=(a1,a2,a3,...,an),b=(b1,b2,b3,...,bn),x=(x1,x2,x3,...,xn)都是n维整数向量,求a*x/b*x的最大值或最小值,其中x[i]只能取0或1,也就是求(a1*x1+a2*x2+a3*x3+...+an*xn)/(b1*x1+b2*x2+b3*x3+...+bn*xn),且xi={0,1},的最值,x取01的意思就是:如果xi取1原创 2016-07-16 09:34:57 · 315 阅读 · 0 评论 -
LA 3971 Assemble / 二分
有n个物品 属性有明智 价格 名字(没用)种类 每种类型选一个 使总价格不超过b 并且最小品质最大 二分品质#include #include #include #include #include #include #include using namespace std;const int MAXN = 1010;int cnt;int n,m;map id;s原创 2013-12-08 13:55:24 · 1201 阅读 · 0 评论 -
TOJ 4373 HDU 4430 ZOJ 3665 Yukari's Birthday / 二分
Yukari's Birthday时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte描述Today is Yukari's n-th birthday. Ran and Chen hold a celebration party for her. Now comes the most important part, b原创 2013-10-30 17:43:58 · 1055 阅读 · 0 评论 -
UVa 11384 Help is needed for Dexter / 二分
这题和zoj的豆子那题差不多 每次对半分就行了#include int dfs(int n){ if(n == 1) return 1; return dfs(n/2) + 1;}int main(){ int n; while(scanf("%d",&n)!=EOF) { printf("%d\n",dfs(n)); } return 0;}原创 2013-10-26 23:45:13 · 1100 阅读 · 0 评论 -
BZOJ 1189 紧急疏散evacuate 二分+BFS+最大流
建图的时候需要拆点,按照每一个时间点拆点,主要可以保证每次只有一个人走出门。BFS处理出人到门的距离二分答案,判断是否可以建边,S指向每一块空地,空地到门如果可以建边就建一条容量为x的边每个门按照时间拆点,保证单位时间内走一次,然后跑最大流原创 2016-07-22 09:02:21 · 409 阅读 · 0 评论