摘要:
/*二分法:对dollar二分从mx和sum处开始二分*/#include <iostream>#define Max 100000using namespace std;int n,m;int dollar[Max];bool judge(int x)//计算当mid为x时可以分成多少个"fajomonths"并与m比较。{int num=1;int sum=0;for (int i=0;i<n;i++){sum+=dollar[i];if(sum>x){sum=dollar[i];num++;}}if(num<=m)return true; 阅读全文
摘要:
/*对rock间的距离进行二分*/#include<iostream>#include <algorithm>#define Max 50005using namespace std;int rock[Max];int l,n,m,mn;bool judge(int x)//判断可移除的rock是否大于m{int del=0;for (int i=1,j=0;i<=n+1;){if(rock[i]-rock[j]<=x){del++;i++;}else{j=i;i++;}}if(del>m)return true;//right=mid-1;elser 阅读全文