nyoj586||poj2456 二分+贪心
来源:互联网 发布:ifconfig修改mac地址 编辑:程序博客网 时间:2024/04/30 09:32
完全看不懂题意。。。。百度搜搜才看懂题意 然后就参考代码了 和yougth的最大化()nyoj914差不多的方法 二分+贪心
#include <stdio.h>#include <algorithm>using namespace std;int c,a[100005],n;bool judge(int k){int p=a[0],cnt=1;//也就这里注意点 从1开始 自己想想为啥for(int i=1;i<n;i++){if(a[i]-p>=k)cnt++,p=a[i];if(cnt>=c)return true;}return false;}int bin_search(int right)//步步逼近最小值。{int left=0,mid;while(left<=right){mid=(left+right)/2;if(judge(mid))left=mid+1;elseright=mid-1;}return left-1;}int main(){while(scanf("%d %d",&n,&c)!=EOF){for(int i=0;i<n;i++)scanf("%d",&a[i]);sort(a,a+n);//从小到大排序printf("%d\n",bin_search(a[n-1]-a[0]));//a[n-1]-a[0]最大差值}return 0;}
1 0
- nyoj586||poj2456 二分+贪心
- nyoj586 poj2456二分+贪心
- poj2456-Aggressive cows(nyoj586)【贪心-二分】
- poj2456(贪心+二分)
- Poj2456二分+贪心
- POJ2456 Aggressive cows(二分+贪心)
- POJ2456(Aggressive cows)(贪心+二分)
- poj2456(二分最大化最小值,贪心)
- POJ2456 二分
- POJ2456 二分
- POJ2456【二分】
- poj2456(二分)
- 【SPOJ-AGGRCOW】【BZOJ1734】【POJ2456】Aggressive cows【二分】【贪心】
- POJ2456 Aggressive cows (二分)
- poj2456 二分搜索
- poj2456(二分搜索)
- POJ2456 Aggressive cows 二分
- POJ2456 二分搜索
- 贫血模型和充血模型
- Codeforces Round #145 (Div. 1, ACM-ICPC Rules)A
- 学习Java的第一天
- 递归算法实现全排列
- JAVA API 异常处理
- nyoj586||poj2456 二分+贪心
- 搭建Web项目
- Symmetric Tree
- 传感器
- 例题3-2
- doFilter如何使用
- HDU ACM 1286-找新朋友-欧拉phi函数
- 代码片1
- url正则