随笔分类 - 二分
hdu 4606 Occupy Cities
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4606两点之间如果有线段相隔的话,他们的最短路就需要经过线段的端点把所有线段的端点也加入点数组中,求任意两个点的距离(可达的话,没有其他线段阻挡)然后对所有的点进行floyd 可以求出任意两点的最短路然后二分所需容量 根据容量和要求的顺序进行建图,求最小覆盖路径(匈牙利算法)代码:#include#include#include#include#include#include#include#include#include#include#include#include#include#include#inc
阅读全文
TopCoder SRM 582 SpaceWarDiv1
摘要:这个题比较简单,不需要多说,最直观的解法就是二分,思路很清晰,写起来也方便。但仅满足于这个是不够的,看了别人的代码,好像有O(n) 的解法,后来想了一下,的确可以,所以说,一道题可以有不同的解法。而且我个人认为,每一种解法,都是一种思想。二分代码:#include<iostream>#include<cstdio>#include<vector>#include<stack>#include<cstring>#include<queue>#include<algorithm>#include<cmath&
阅读全文
hdu 2141 Can you find it?
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2141二分代码:#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<map>#include<vector>#include<stack>#include<set>#include<map>#include<queue>#include<deque>#include<algo
阅读全文
1379. Cups Transportation
摘要:http://acm.timus.ru/problem.aspx?space=1&num=1379二分 最短路代码:#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<map>#include<vector>#include<stack>#include<set>#include<map>#include<queue>#include<algorithm>#
阅读全文
E. Printer
摘要:http://codeforces.com/contest/253/problem/E对优先级进行二分 每次给一个优先级就模拟一下看是否合格 不合格就二分调整需要注意的地方 所给T的范围会超 int (就是这点敲代码时忽略了 wa 了很久 细节呀) 还有就是优先级没有重的情况代码:#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<map>#include<vector>#include<stack>#inclu
阅读全文
poj 3621 Sightseeing Cows
摘要:http://poj.org/problem?id=3621分数规划+二分 最优比率环 不是很难 本题中没有说明从哪个点开始 不过好像默认为1就可以过 poj数据又水了里面的用spfa判定部分还是不太懂代码及其注释:#include<iostream>#include<stdio.h>#include<algorithm>#include<math.h>#include<queue>#include<string.h>using namespace std;const double eps=1e-5;const int N
阅读全文
poj 2976 Dropping tests
摘要:http://poj.org/problem?id=2976通过二分 不断的移动左右边界 知道满足精度#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>#define LL long longusing namespace std;const double eps=1e-4;const int N=1005;double a[N];double b[N];double c[N];bool cmp(double x,double y){ return x>
阅读全文
poj 3122 Pie
摘要:http://poj.org/problem?id=3122#include<iostream>#include<string>#include<cstring>#include<cmath>#include<cstdio>#include<algorithm>using namespace std;const double K=1e-4;const double PI=acos(-1);const int N=10005;double size[N];int n,F;bool toosmall(double k){ in
阅读全文
poj 1905 Expanding Rods
摘要:http://poj.org/problem?id=1905#include<iostream>#include<string>#include<cstring>#include<cmath>#include<cstdio>#include<algorithm>using namespace std;const double K=1e-10;const double PI=acos(-1);int main(){ double L,n,C; while(cin>>L>>n>>C) { i
阅读全文
poj 3258 River Hopscot
摘要:http://poj.org/problem?id=3258#include<iostream>#include<string>#include<cstring>#include<cstdio>#include<algorithm>using namespace std;const int N=50005;int Dist[N];int L,n,m;bool toosmall(int k){ int sum=0; int pre=0; for(int i=1;i<=n;++i) { if(Dist[i]-pre<k) {
阅读全文
poj 3273 Monthly Expense
摘要:http://poj.org/problem?id=3273给你每天的花费,让你分成m组 要求各组的和中的最大值越小越好二分查找#include<iostream>using namespace std;const int N=100001;int n,m;bool toosmall(int k,int money[]){ int count=1;//k吧花费分成的组数,开始为一组 int sum=0; for(int i=1;i<=n;++i) { if(sum+money[i]>k)//如果超过k 应增加一组,所以count加一 sum更新重计 ...
阅读全文