POJ 3258 River Hopscotch 二分枚举
题目:http://poj.org/problem?id=3258
又A一道,睡觉去了。。
#include <stdio.h>
#include <algorithm> int d[];
int s, n, m; bool judge(int mid)
{
int sum = , cnt = ;
for(int i = ; i <= n+; i++)
{
sum += d[i] - d[i-];
if(sum < mid)
cnt++;
else
sum = ;
}
if(cnt > m)
return ;
else return ;
} int main()
{
scanf("%d %d %d", &s, &n, &m);
for(int i = ; i <= n; i++)
{
scanf("%d", &d[i]);
}
d[] = ;
d[n+] = s;
std::sort(d, d+n+); int low = , high = s+, mid;
while(low < high)
{
mid = (high + low) / ;
if(judge(mid))
high = mid;
else
low = mid + ;
}
printf("%d\n", low-);
return ;
}
POJ 3258 River Hopscotch 二分枚举的更多相关文章
- POJ 3258 River Hopscotch(二分答案)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21939 Accepted: 9081 Desc ...
- [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6697 Accepted: 2893 D ...
- poj 3258 River Hopscotch(二分+贪心)
题目:http://poj.org/problem?id=3258 题意: 一条河长度为 L,河的起点(Start)和终点(End)分别有2块石头,S到E的距离就是L. 河中有n块石头,每块石头到S都 ...
- poj 3258 River Hopscotch 二分
/** 大意:给定n个点,删除其中的m个点,其中两点之间距离最小的最大值 思路: 二分最小值的最大值---〉t,若有距离小于t,则可以将前面的节点删除:若节点大于t,则继续往下查看 若删除的节点大于m ...
- 二分搜索 POJ 3258 River Hopscotch
题目传送门 /* 二分:搜索距离,判断时距离小于d的石头拿掉 */ #include <cstdio> #include <algorithm> #include <cs ...
- POJ 3258 River Hopscotch
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11031 Accepted: 4737 ...
- poj 3258 River Hopscotch 题解
[题意] 牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值 ...
- POJ 3258 River Hopscotch (binarysearch)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5193 Accepted: 2260 Descr ...
- POJ 3258 River Hopscotch(二分答案)
嗯... 题目链接:http://poj.org/problem?id=3258 一道很典型的二分答案的题目,和跳石头太像了!! 这道题的题目很显然,求最小中的最大值,注意这道题石头的位置不是从小到大 ...
随机推荐
- SQL Server 2008 游标使用实例
本文使用以下两张数据库表作为演示对象. 1 游标初探--使用游标进行遍历 declare @classAndStudent table( class_id int, --班级ID class_name ...
- Java加密算法 AES
版权声明:本文为博主原创文章,转载请注明出处. [java] view plain copy print?在CODE上查看代码片派生到我的代码片 package com.stone.security; ...
- 解决Visual Studio 2010新建工程时出现『1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt』错误
VS2010在经历一些更新后,建立Win32 Console Project时会出"error LNK1123" 错误. 解决方案为: 第一步:将:项目|项目属性|配置属性|清 ...
- To Be NUMBER ONE
Problem Description One is an interesting integer. This is also an interesting problem. You are assi ...
- 如何运用管理员身份运行cmd窗口?
所有程序 → 附件 → 命令行提示符 → 鼠标右键“以管理员身份运行”.
- Spring MVC自定义统一异常处理类,并且在控制台中输出错误日志
在使用SimpleMappingExceptionResolver实现统一异常处理后(参考Spring MVC的异常统一处理方法), 发现出现异常时,log4j无法在控制台输出错误日志.因此需要自定义 ...
- commons-fileupload源码学习心得
commons-fileupload依赖于commons-io包. commons-fileupload的使用方法: 1.创建一个文件项目工厂类DiskFileItemFactory. D ...
- CentOs6.8安装Git并安装oh my zsh
(一)git安装 1.下载git2.4.9或其他版本 Index of /pub/software/scm/git git各个版本下载链接: https://www.kernel.org/pub/so ...
- sqlite 数据库打开失败
今天在做Android电子词典的时候,数据库打不开,报错为:Could not open the database in read/write mode. 后来才发现犯了一个低级错误,没有设置权限. ...
- c标准库中字符和数字转换的函数
字符转换为数字: #include<stdlib.h> atoi(); 将字符转换为整型 例:char ch1;int i=atoi(ch ...