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. AWS AutoScaling的一个ScaleDown策略问题以及解决方法

    此文已由作者袁欢授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 1. AWS AutoScaling简介 AutoScaling是AWS的一个重要服务,用来弹性的自动创建(S ...

  2. vue中引入公共方法并使用

    test.js文件(公共js文件) function myFun() { console.log('this is my function') } export { myfun } // 2 expo ...

  3. 洛谷 - P1381 - 单词背诵 - 哈希 - 尺取

    https://www.luogu.org/problemnew/show/P1381 字符串匹配,用哈希总没有错的. 然后就是尺取了,题目要求首先尽可能多覆盖,那么每次尾巴往后面长. 一开始先找到第 ...

  4. 3DMAX 1快捷键及常用操作

    开启,关闭快捷键 ,使用快捷键时要按下这个按钮 快捷键查看与修改 自定义-自定义用户界面(cutomize user interface):设置和查看快捷键 位置变换 Z: 复位---物体被移动飞了的 ...

  5. perl 安装LOG4perl 模块

    环境信息 ubuntu 12.04 64位 桌面版 Log-Log4perl 的介绍网址:http://search.cpan.org/~mschilli/Log-Log4perl-1.49/lib/ ...

  6. LVS-DR VIP和RIP不同网段的配置方法

    http://blog.itpub.net/25723371/viewspace-1446935/

  7. MySQL--表操作1

    这是对自己学习燕十八老师mysql教程的总结,非常感谢燕十八老师. 依赖软件:mysql 系统环境:win 注:本次所有命令都是在命令行上执行 数据库的四大天王操作:增删改查 增删改查都是在对表进行操 ...

  8. 【TeamViewer】v13.2.26558版本 修改ID

    TeamViewer是一款远程协作软件,可以让你在一台机器上操作另一台机器.比如我最近就经常在家里连接公司的电脑进行远程工作.可以说是对于程序员很好用的一个软件. TeamViewer 使用频繁后会被 ...

  9. Maven - settings.xml简易配置Demo

    前言 这里贴一下settings.xml的一个简易配置demo,就是简单配置了:本地的仓库地址.阿里云镜像.指定使用jdk1.8进行编译. 这里使用的Maven是3.5.0版本的. 配置文件demo ...

  10. PostgreSQL-2-用户权限管理

    1.创建与删除用户 CREATE ROLE rolename; 方法1,创建角色 CREATE USER username; 方法2,创建用户 CREATE USER指令创建的用户默认是有登录权限的, ...