51nod 1243 排船的问题(二分)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1243
题意:

思路:
二分来做,每次贪心的把船安排到能安排的最左边即可。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn=+; int n,x,m;
int pos[maxn]; bool judge(int d)
{
int st=*x;
for(int i=;i<=n;i++)
{
while(true)
{
if(st>m) return ;
if(abs(st-x-pos[i])<=d) {st+=*x;break;} //如果绳子小于等于d的话,那么就进行下一艘船
else
{
if(pos[i]<st-x) return ; //如果超过了且木桩在船中心的左边,那肯定是不行的,因为我们船都是贪心的放在最左边的位置
st+=(pos[i]-(st-x)-d); //如果在右边,则移动到正好距离为d的位置点
}
}
}
return ;
} int main()
{
//freopen("in.txt","r",stdin);
scanf("%d%d%d",&n,&x,&m);
for(int i=;i<=n;i++) scanf("%d",&pos[i]);
if(n**x>m) {puts("-1");return ;}
int left=,right=m-,ans;
while(left<=right)
{
int mid=(left+right)>>;
if(judge(mid)) {ans=mid;right=mid-;}
else left=mid+;
}
printf("%d\n",ans);
return ;
}
51nod 1243 排船的问题(二分)的更多相关文章
- 51 nod 1243 排船的问题
1243 排船的问题http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1243 题目来源: Codility 基准时间限制:1 ...
- 51nod 1243 二分+贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1243 1243 排船的问题 题目来源: Codility 基准时间限制: ...
- 51nod 1105(第K大数 二分套二分)
题目链接:http://www.51nod.com/onlineJudge/submitDetail.html#!judgeId=620811 参考自:https://blog.csdn.net/f_ ...
- 51nod 1640 天气晴朗的魔法 二分 + 克鲁斯卡算法(kruskal算法) 做复杂了
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1640 一开始想的时候,看到要使得最大值最小,那这样肯定是二分这个最大值了 ...
- 51nod - 1278 相离的圆 (二分)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 因为圆心都在x轴上,把每个圆转化成线段后,按线段的起点排序,那么对 ...
- 51nod 第K大区间2(二分+树状数组)
题目链接: 第K大区间2 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 160 定义一个长度为奇数的区间的值为其所包含的的元素的中位数.中位数_百度百科 现给出n个数,求将所有长度为 ...
- 51Nod 1557 两个集合(二分)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1557 题意: 小X有n个互不相同的整数: p1,p2,...,pn .他 ...
- 51nod 1686 第K大区间 二分瞎搞
题目: 定义一个区间的值为其众数出现的次数. 现给出n个数,求将所有区间的值排序后,第K大的值为多少. 题解: 答案明显单调,我们考虑二分答案. 转化为判定问题后我们需要观察到一个性质: 如果一个区间 ...
- 51NOD 1962 区间计数 单调栈+二分 / 线段树+扫描线
区间计数 基准时间限制:1.5 秒 空间限制:262144 KB 分值: 80 两个数列 {An} , {Bn} ,请求出Ans, Ans定义如下: Ans:=Σni=1Σnj=i[max{ ...
随机推荐
- mybatis中使用where in查询时的注意事项
我使用的时候collection值为mapper的参数名如:int deleteRoleByUserIds(@Param("userIds") String[] userIds); ...
- MongoDB复制集的工作原理介绍(二)
复制集工作原理 1)数据复制原理 开启复制集后,主节点会在 local 库下生成一个集合叫 oplog.rs,这是一个有限集合,也就是大小是固定的.其中记录的是整个mongod实例一段时间内数据库的所 ...
- container / pull-left
<div class="container"> <h2>实例</h2> <div class="pull-left"& ...
- MVC杂碎笔记
MVC页面中@相当于aspx中的<%%>一样,@后面可以写代码的,一般用来放变量的 -- 在Controller中方法的前面加[HttpGet]表示该方法只处理http的 GET 请求, ...
- CMFCPropertyGridProperty的使用
设定初始值 CString str(_T("Button")); COleVariant cOlevariant(str); pTypeProperty->SetOrigin ...
- Lintcode: Heapify && Summary: Heap
Given an integer array, heapify it into a min-heap array. For a heap array A, A[0] is the root of he ...
- SSH无密码登录:只需两个简单步骤 (Linux)
最后更新 2017年4月8日 分类 最新文章 服务器安全 标签 RSA SSH Key 非对称加密 如果你管理一台Linux服务器,那么你就会知道每次SSH登录时或者使用scp复制文件时都要输入密码是 ...
- 来自阿里妈妈的iconfont(转)
转自http://www.augsky.com/775.html 随便说说两者的优缺点 其实主要是说iconfont的优点和Font Awesome的缺点.-_-|||iconfont的图标库相当巨大 ...
- C/S模型之TCP群聊
说明:利用TCP协议和多线程实现群聊功能.一个服务器,多个客户端(同一个程序多次启动).客户端向服务端发送数据,由服务端进行转发到其他客户端. /服务端 // WSASever.cpp : 定义控制台 ...
- javascript中父、子页面间调用
本文主要转自:http://www.360doc.com/content/11/0525/17/6161903_119333834.shtml http://zh ...