【SPOJ】【AGGRCOW】
来源:互联网 发布:dsa p57 数据升级工具 编辑:程序博客网 时间:2024/06/05 10:44
总结:函数之间存在依赖。 然后一处修改了但是忘记修改另外的一处了。。。
#include <iostream>#include <cstring>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <string>#include <cstdlib>#include <cstdio>#include <algorithm>using namespace std;int Case;int n,m;int arr[1000010];bool ok(int interv){ int last = 1; arr[0] = 0; //cout << arr[last - 1] << endl; for(int i=2;i<=m;i++) { int cur = last + 1; while(cur <= n && arr[cur] - arr[last] < interv) cur ++; if(cur > n) { return false; } last = cur; } return true;}int main(){//freopen("1.txt","r",stdin);scanf("%d",&Case);while(Case --){ memset(arr,0,sizeof(arr));scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){scanf("%d",&arr[i]);}arr[0] = -0x3f3f3f3f;sort(arr,arr+n+1);int ans = -1;int low = 0;int high = 1000000000;while(low <= high){int mid = (low + high) / 2;if(ok(mid)){ans = mid;low = mid + 1;}else{high = mid - 1;}}//cout << m << endl;arr[0] = 0;//cout << ok(7) << endl;printf("%d\n",ans);}}
0 0
- 【SPOJ】【AGGRCOW】
- SPOJ AGGRCOW 二分枚举
- 【SPOJ-AGGRCOW】【BZOJ1734】【POJ2456】Aggressive cows【二分】【贪心】
- spoj297 AGGRCOW
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- Java编程思想 笔记
- 遗留系统的技术栈迁移
- 75Sort Colors
- xutils框架的使用方法
- HFC
- 【SPOJ】【AGGRCOW】
- [Microsoft][ODBC 驱动程序管理器] 无效的描述器索引
- 存储一个图的内存开销
- uva 10905 Children's Game 儿童游戏
- GRE写作必备句型
- openrefactory/c之添加自反任务(四)
- nginx----queue
- 自动生成地图 物体 Generator
- shell学习四十五天----xargs