http://acm.nyist.net/JudgeOnline/problem.php?pid=586

http://poj.org/problem?id=2456

解题思路:最大化最小值二分答案即可

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 
 5 int a[];
 6 int n, c, i;
 7 
 8 int cmp(const void *a, const void *b){
 9     return *(int *)a - *(int *)b;
 }
 
 bool check(int x){
     int cnt = , temp = a[];
     for(i = ; i < n; i++){
         if(a[i] - temp > x){
             cnt++;
             temp = a[i];
             if(cnt >= c){//如果能装下c头牛
                 return true;
             }
         }
     }
     return false;
 }
 
 void solve(){
     //二分搜索最大的距离
     int l = , r = a[n - ] - a[];
     while(l <= r){
         int mid = (l + r) >> ;
         if(check(mid)){
             l = mid + ;
         }
         else{
             r = mid - ;
         }
     }
     printf("%d\n", l);
 }
 int main(){
     while(scanf("%d %d", &n, &c) != EOF){
         for(i = ; i < n; i++){
             scanf("%d", &a[i]);
         }
         qsort(a, n, sizeof(a[]), cmp);
         solve();
     }
     return ;

49 }

nyoj-586-疯牛|poj-2456-Aggressive cows的更多相关文章

  1. poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分

    poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分 题目链接: nyoj : http://acm.nyist.net/JudgeOnline/ ...

  2. 二分搜索 POJ 2456 Aggressive cows

    题目传送门 /* 二分搜索:搜索安排最近牛的距离不小于d */ #include <cstdio> #include <algorithm> #include <cmat ...

  3. POJ 2456 Aggressive cows (二分 基础)

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7924   Accepted: 3959 D ...

  4. POJ 2456 Aggressive cows (二分)

    题目传送门 POJ 2456 Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) s ...

  5. [ACM] poj 2456 Aggressive cows (二分查找)

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5436   Accepted: 2720 D ...

  6. POJ 2456 Aggressive cows

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11192   Accepted: 5492 ...

  7. POJ 2456 Aggressive cows(二分答案)

    Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22674 Accepted: 10636 Des ...

  8. POJ - 2456 Aggressive cows 二分 最大化最小值

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18099   Accepted: 8619 ...

  9. poj 2456 Aggressive cows 贪心+二分

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25944   Accepted: 11982 ...

  10. POJ 2456 Aggressive cows(贪心 + 二分)

    原题链接:Aggressive cows 题目大意:农夫 建造了一座很长的畜栏,它包括  个隔间,这些小隔间依次编号为. 但是, 的  头牛们并不喜欢这种布局,而且几头牛放在一个隔间里,他们就要发生争 ...

随机推荐

  1. yarn 基础

    创建: 2019/04/06  安装 mac brew install yarn  升级 brew upgrade yarn 确认是否成功 yarn --version  初始化项目 yarn ini ...

  2. Unity3D中常用的数据结构总结与分

    阅读目录 1.几种常见的数据结构 2.几种常见数据结构的使用情景 来到周末,小匹夫终于有精力和时间来更新下博客了.前段时间小匹夫读过一份代码,对其中各种数据结构灵活的使用赞不绝口,同时也大大激发了小匹 ...

  3. 51nod1640(kruscal)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1640 题意:中文题诶- 思路:kruscal 题目要求是在边权 ...

  4. 2013 Noip提高组 Day1

    3285 转圈游戏 2013年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description ...

  5. [Xcode 实际操作]八、网络与多线程-(20)时间控件Timer定时功能

    目录:[Swift]Xcode实际操作 本文将演示时间控件Timer定时功能的使用. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit cl ...

  6. XHTML学习笔记 part1

    XHTML: 可扩展超文本标记语言 HTML语言最开始是用来描述文档的结构,如标题,段落等标记,后来HTML有增加了一些控制字体,对齐等方面的标记和属性,这样做的结果是HTML既可以用来描述文档的结构 ...

  7. tensorflow:实战Google深度学习框架第四章02神经网络优化(学习率,避免过拟合,滑动平均模型)

    1.学习率的设置既不能太小,又不能太大,解决方法:使用指数衰减法 例如: 假设我们要最小化函数 y=x2y=x2, 选择初始点 x0=5x0=5  1. 学习率为1的时候,x在5和-5之间震荡. im ...

  8. Qt 2D绘图之三:绘制文字、路径、图像、复合模式

    一.绘制文字 除了绘制图形以外,还可以使用QPainter::darwText()函数来绘制文字,也可以使用QPainter::setFont()设置文字所使用的字体,使用QPainter::font ...

  9. NOI2012 D2T1扩展欧几里得

    #include <bits/stdc++.h> using namespace std; #define ll long long ll extgcd(ll a,ll b,ll & ...

  10. jruby+watir-webdriver+cucumber自动化测试环境配置

    1.安装java运行时环境,且配置环境变量 2.安装jruby环境,建议选择安装1.6.8或1.6.7版本的 3.安装需要的gem包 gem install activerecord -v='3.0. ...