首页 > 代码库 > poj 2456
poj 2456
#include <iostream>#include <cstdio>#include <algorithm>#define range(i,a,b) for (int i=a;i<=b;i++)using std::cin;using std::cout;using std::sort;// namespace std has "left" and "right"// if you use them as global variables,there will be an errorconst int maxn = 100000;int pos[maxn+1];int left,right;int n,m;bool check(int val){ int ans(1); int last(1); range(c,2,n) if (pos[c]-pos[last]>=val) { last = c; ans++; } return ans >= m;}int main(){ cin>>n>>m; range(i,1,n) { scanf("%d",&pos[i]); } sort(pos+1,pos+1+n); left = 0; right = pos[n] - pos[1]; range(c,1,60)//i am lazy { int mid = (right + left) >> 1; if (check(mid)) { left = mid; } else { right = mid; } } cout<<(left+right)/2; return 0;}
poj 2456
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。