POJ 3258 River Hopscotch 二分答案
来源:互联网 发布:保健品网络销售好做吗 编辑:程序博客网 时间:2024/06/05 18:07
题目链接:http://poj.org/problem?id=3258
题目描述大致为,在0~L的长度上,有N块石头,可以移走<=M块石头,求得两个石头之间最短距离的最大值。
首先对石头的位置坐标按从小到大排序,之后在0~L的范围内二分每次所走的距离,看是否满足移走石头数<=M的条件,如果移走石头数多于M,则更改上界R,否则更改下界L,逐渐将L,R的范围缩小,最后求得满足题意的答案。
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int a[50005];int s,n,m;int v[50005];int work(int mid){ int tmp=0; int ans=0; for(int i=1;i<=n;i++) { if(a[i]-a[tmp]<mid) ans++; else tmp=i; } if(s-a[tmp]<mid) ans++; return ans;}int main(){ while(cin>>s>>n>>m) { for(int i=1;i<=n;i++) cin>>a[i]; a[0]=0;a[n+1]=s; sort(a,a+1+n); int l=0,r=s; int mid; while(l<=r) { mid=(l+r)/2; int step=work(mid); if(step<=m) l=mid+1; else r=mid-1; } cout<<l-1<<endl; }}
0 0
- poj 3258 River Hopscotch(二分答案)
- poj 3258 River Hopscotch 二分答案
- POJ 3258 River Hopscotch 二分答案
- POJ 3258 River Hopscotch 二分
- POJ 3258 River Hopscotch 二分
- poj-3258-River Hopscotch-二分
- River Hopscotch - POJ 3258 二分
- poj 3258 River Hopscotch 【二分】
- POJ 3258 River Hopscotch (二分)
- POJ 3258 River Hopscotch(二分)
- POJ - 3258 River Hopscotch 二分
- POJ 3258 River Hopscotch (二分)
- poj 3258 River Hopscotch二分
- 【POJ 3258】 River Hopscotch (二分)
- poj 3258 River Hopscotch 【二分】
- POJ 3258 River Hopscotch 二分
- POJ 3258 River Hopscotch (二分)
- *Poj 3258 二分 River Hopscotch
- 使用Navicat for Oracle新建表空间、用户及权限赋予
- RESTful 的webservice
- 开源项目:3D旋转动画Rotate3dAnimation.java
- Dojo-最佳实践如何防止浏览器内存泄露
- Java Proxy
- POJ 3258 River Hopscotch 二分答案
- Oracle RAC Failover 详解
- 单例模式&工厂模式(简介)
- 利用BeanUtils在对象间复制属性
- TCP/IP协议基础(总结)
- c++ 队列基本操作实现
- web前端设计
- Hibernate实战_笔记5(Hibernate、EJB3、JPA)
- PAT (Advanced) 1046. Shortest Distance (20)