binary search

POJ 2456 Aggressive cows

解説 蟻本に書いてある。 #include <iostream> #include <algorithm> #include <vector> using namespace std; const int INF = 1 << 29; int n,m,a; vector<int> x; bool C(int d){ int last = 0; for(int i = 1; i < m; i++){ int crt = last + 1; while(crt < n && x[crt] - x[last] < d) cr</int></vector></algorithm></iostream>…

POJ 1064 Cable master

解説 蟻本に解法が載ってある。 二部探索まだまだ身についてない。 #include <iostream> #include <cmath> using namespace std; const int INF = 1 << 29; int n,k; double l[10001]; bool C(double x){ int num = 0; for(int i = 0; i < n; i++) num += (int)(l[i] / x); re</cmath></iostream>…