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. 我叫mt2.0更新公告

    一.2.0版<PVP的远征>军费发放 简体服<我叫MT>2.0版本<PVP的远征>更新在即!为备战新版本,我们宣布10天后(3月10日)发放军费振奋军心. 简体服3 ...

  2. 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:9. 自定义委托事件方法

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

  3. export default 和 export 的使用方式(六)

    一:ES6 的导入模块方式和暴露对象方式: ES6 中导入模块使用:import 模块名称 from '模块标识符':import '表示路径': 在 ES6 中使用 export default 和 ...

  4. TTM-To the moon

    传送门 查询历史版本,回到历史版本,这个题目显然是用主席树,好像就没了! 但是这里的修改是区间修改,众所周知主席树的空间复杂度是\(nlog(n)\)的,区间修改会导致主席树的开点到达一个相当恐怖的数 ...

  5. Tinghua Data Mining 6

    Networks 多层感知机 不是说这个神经网络要与人的大脑神经完全相似,也不是说要多么的强大,而是在一定程度上模拟了人脑神经元的能力,就足够了 为什么要w0呢,因为没有w0超平面一定会经过原点,所以 ...

  6. laravel-admin 自定义导出表单

    官方导出文档 laravel-admin自带的导出excel会导出与此模型关联的其他数据.所以参考官方文档调整代码 文章表:id,title,user_id 用户表:id,username //文章模 ...

  7. 洛谷P2473||bzoj1076 [SCOI2008]奖励关

    https://www.luogu.org/problemnew/show/P2473 https://www.lydsy.com/JudgeOnline/problem.php?id=1076 不会 ...

  8. Xenu使用随记

    经试验发现,如果配置了host进行网站检测时,Xenu和浏览器一样,都需要配置了host之后,重新打开Xenu程序(浏览器),host的配置才能生效.

  9. 调用submit()方式提交表单

    今天在看高级程序设计时看到的这样一段话: 在以调用submit()方法的形式提交表单时,不会触发submit事件 写了一个小例子做了下测试,的确如此: <form id="fm&quo ...

  10. B. Dispersed parentheses 记忆化搜索 + 括号序列的状压表示

    http://codeforces.com/gym/100633/problem/B B. Dispersed parentheses time limit per test 2 seconds me ...