随笔分类 - 二分法
基础算法
摘要:P1102 A-B 数对 #include<map> #include<iostream> #include<vector> using namespace std; map<int,int> m; vector <int> ma; long long ans=0; int main() { int
阅读全文
摘要:P2249 【深基13.例1】查找#include<cstdio>using namespace std;int a[1000009];int lb(int a[],int l,int r,int key){ int ans=-1; int mid; while(l<=r) { mid=((r-l)
阅读全文
摘要:C++STL提供几个二分查找的方法。 lower_bound() (1)原型template< class ForwardIt, class T >ForwardIt lower_bound( ForwardIt first, ForwardIt last, const T& value );返回第
阅读全文
摘要:二分查找算法问题一、在一个有序的序列(不降序列)中查找指定值的算法,查找成功返回它所在的位置,否则返回-1int binarySearch(int a[],int l,int r,int x){ int ans=-1; while(l<=r) { int m=l+(r-l)/2; if (a[m]=
阅读全文
摘要:#include<vector> #include<iostream> #include<algorithm> using namespace std; vector <int> a; vector <int>::iterator ita; int main() { int q,n,x; cin>>
阅读全文