二分
everlasting__
'-'
展开
-
bzoj 1614: [Usaco2007 Jan]Telephone Lines架设电话线 二分+最短路
→题目链接← 二分ans,小于等于ans的边的距离看作0,大于ans的看作1 每次跑一下最短路,dis[n]代表有多少边是需要免费的 所以如果dis[n] 别忘了输出-1 代码: #include #include #include #include using namespace std; struct node{ int to,len; int now; }; v原创 2017-08-14 14:24:36 · 307 阅读 · 0 评论 -
bzoj 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 二分+最大流
→题目链接← 二分答案,每次把边长小于mid的边放到图中,正反的边容量都为1,跑最大流 然后用最大流和T判断一下,如果大于T返回true,否则false 代码: #include #include #include #include #include #define ll long long #define inf 10000001 using namespace std;原创 2017-08-16 10:54:15 · 282 阅读 · 0 评论 -
bzoj 1720: [Usaco2006 Jan]Corral the Cows 奶牛围栏 二分
→题目链接← 先按奶牛的横坐标排序,然后二分答案 判断圈住多少奶牛暴力搞就好,N 代码: #include #include #include #include #include #include #define inf 999999999 using namespace std; struct point{ int x,y; friend bool operator <原创 2017-08-16 09:28:07 · 269 阅读 · 0 评论 -
bzoj 3412: [Usaco2009 Dec]Music Notes乐谱
→题目链接← 维护前缀和,对于每次询问找到第一个大于它的数(也就是upper_bound)的下标,就是答案 手写可以二分找 用stl可以用upper_bound 代码: #include #include #include using namespace std; int n,m; int sum[50050]; int main(){ scanf("%d%d",原创 2017-08-25 14:15:54 · 374 阅读 · 0 评论 -
bzoj 3372: [Usaco2004 Feb]Moo University -- Financial Aid 财政补助 二分
→题目链接← 【想说的话】 期中考试gg了... 写发水题压压惊 【题解】 用两个数组,一个按分数从小到大排序,一个按价格从小到大排序 在按分数排序的数组上进行二分,把它当作中位数,然后在另一个数组中扫一遍找到两边的数,判断是否合法 复杂度O(nlogn) [2018-10-21]:突然发现没有单调性,所以二分是假的,但是数据太弱了所以过了,还是优先队列吧... ...原创 2017-11-05 19:47:10 · 266 阅读 · 0 评论