zoukankan      html  css  js  c++  java
  • poj 2456

    /*
      题意:有n个牛棚,给出他们的位置,有m头牛,安排一种方案,使得相邻牛之间最小距离最大。
    */

    #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 error const 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; }
  • 相关阅读:
    python day05
    python day04
    python day03
    python day02
    计算机基本了解
    流程控制
    MFC程序中创建文件夹(文件路径)
    svn移动目录并且保存历史日志
    C++单例模式的问题
    PtInRect 的详细范围
  • 原文地址:https://www.cnblogs.com/dandi/p/4063473.html
Copyright © 2011-2022 走看看