POJ 3258 River Hopscotch

本题与poj2456非常相似,只需更改几个条件
使用二分搜索加快速度
poj 2456:https://blog.csdn.net/qq_43768149/article/details/86754555

#include <cstdio>
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod=1e9+7;
const ll MOD=1e9+7;
const ll inf = 0x3f3f3f3f;
const int maxn = 100005;
const int maxa = 300005;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll n,m,l;
ll str[50005];
bool C(int x)
{
	int last=0;
	
	 for(int i=0;i<n-m;i++)
	 {
	 	int cur=last+1;
	 	while(cur<=n&&str[cur]-str[last]<x)
	 	{
	 		cur++;
		 }
		 if(cur>n)

		 return 0;

			last=cur;
	 }
	 return 1;

}
void solve()//二分 
{
	ll l=0,r=inf;
	while(r-l>1)
	{
		ll mid=(l+r)/2;
		if(C(mid)) l=mid;
		else
		r=mid;
	} 
	cout<<l<<endl;
	
	
}

int main()
{
	cin>>l>>n>>m;
	for(int i=1;i<=n;i++)
	
	{
		cin>>str[i];
	}
if(m==n)
{
	cout<<l<<endl;
	return 0; 
}
	str[n+1]=l;
	sort(str+1,str+n+1);
	solve();
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值