P2855 [USACO06DEC]河跳房子River Hopscotch

二分+贪心

每次二分最小长度,蓝后检查需要去掉的石子数是否超过限制。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 50010
int n,m,L,a[N];
bool check(int lim){
int k=;
for(int i=,j=;i<=n;++i){
if(a[i]-a[j]<lim) ++k;
else j=i;
}return k<=m;
}
int main(){
scanf("%d%d%d",&L,&n,&m); a[++n]=L;
for(int i=;i<n;++i) scanf("%d",&a[i]);
sort(a+,a+n+);
int l=,r=L;
while(l<r){
int mid=l+((r-l)>>);
if(check(mid)) l=mid+;
else r=mid;
}printf("%d",check(l)?l:l-);
return ;
}

bzoj1650 / P2855 [USACO06DEC]河跳房子River Hopscotch / P2678 (noip2015)跳石头的更多相关文章

  1. POJ 3258 River Hopscotch(二分答案)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21939 Accepted: 9081 Desc ...

  2. 【POJ - 3258】River Hopscotch(二分)

    River Hopscotch 直接中文 Descriptions 每年奶牛们都要举办各种特殊版本的跳房子比赛,包括在河里从一块岩石跳到另一块岩石.这项激动人心的活动在一条长长的笔直河道中进行,在起点 ...

  3. River Hopscotch(二分POJ3258)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9263 Accepted: 3994 Descr ...

  4. River Hopscotch(二分最大化最小值)

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9923   Accepted: 4252 D ...

  5. POJ 3258 River Hopscotch

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11031   Accepted: 4737 ...

  6. POJ 3258 River Hopscotch (binarysearch)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5193 Accepted: 2260 Descr ...

  7. POJ3285 River Hopscotch(最大化最小值之二分查找)

    POJ3285 River Hopscotch 此题是大白P142页(即POJ2456)的一个变形题,典型的最大化最小值问题. C(x)表示要求的最小距离为X时,此时需要删除的石子.二分枚举X,直到找 ...

  8. POJ--3258 River Hopscotch (最小值最大化C++)

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15273   Accepted: 6465 ...

  9. River Hopscotch

    River Hopscotch http://poj.org/problem?id=3258 Time Limit: 2000MS   Memory Limit: 65536K Total Submi ...

随机推荐

  1. Flask 学习篇一: 搭建Python虚拟环境,安装flask,并设计RESTful API。

    前些日子,老师给我看了这本书,于是便开始了Flask的学习 GitHub上的大神,于是我也在GitHub上建了一个Flask的项目. 有兴趣可以看看: https://github.com/Silen ...

  2. POJ 1417 - True Liars - [带权并查集+DP]

    题目链接:http://poj.org/problem?id=1417 Time Limit: 1000MS Memory Limit: 10000K Description After having ...

  3. 【紫书】BigInteger 高精度类型 原书上有一个bug:A+B!=B+A

    存个代码 struct BigInterger { static const int BASE = 1e8; ; vector<int> s; BigInterger() { *this ...

  4. CodeForces - 768C Jon Snow and his Favourite Number 桶排

    https://vjudge.net/problem/CodeForces-768C 题意:n个数,k次操作,x.每次操作先排序,再让奇数位置上的数据a[i]:=a[i] XOR x;   k< ...

  5. python3学习笔记(3)_dict-set

    # !/usr/bin/env python3 # -*- coding:utf8 -*- #dict 和 set #dict dictionary 用于存放 键值对的, 无序,key 不可变 #姓名 ...

  6. mysql数据库的相关练习题及答案

    表结构示意图: 表结构创建语句: class表创建语句 create table ) not null)engine=innodb default charset=utf8; student表创建语句 ...

  7. 读取Excel列,转换为String输出(Java实现)

    需要导入的jar包 具体实现 public class ColumnToString { public static void main(String[] args) { new ColumnToSt ...

  8. Ucenter社区服务搭建

    1.搭建lamp环境yum  –y  install  httpd  php  php-mysql  mysql  mysql-server 2启动服务   3.设置服务开机自动启动 4.上传UCEN ...

  9. 使用PHP创建一个REST API(译)

    最近API在网络领域有些风靡,明确的说是REST的影响力.这实在没什么好惊讶的,因为在任何编程语言中,消费REST API都是非常的容易.构建它也非常的简单,因为本质上你不会用到任何那些已存在很久的H ...

  10. SSM请求的响应

    1.请求响应文本到页面直接用pw.println("文本信息");打印到页面: 2.如果请求方法前不加@ResponseBody,返回字符串直接转发到对应的页面: 3.如果请求方法 ...