Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

ac代码

Posted by ffouzhe at 2016-02-21 00:18:59 on Problem 3258
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[50005];
bool C(ll x,int n);
ll l;
int m,n;
int main()
{
	while(~scanf("%I64d%d%d",&l,&m,&n))
	{
		a[0]=0;
		for(int i=1;i<=m;i++)
		scanf("%d",&a[i]);
	    sort(a,a+m+1);
	    ll ub=0,lb=l,ans;
	    while(lb>=ub)
	    {
		  ll mid=(lb+ub)>>1;
		  if(C(mid,m-n))
		  {
		  	ub=mid+1;
		  	ans=mid;
		  }
		  else
		  lb=mid-1;
	    }
	    printf("%I64d\n",ans);
	}
	
}
bool C(ll x,int n)
{
	int pre=0,crt=1;
	int ans=0;
	for(crt=1;crt<=m;crt++)
	{
		if(a[crt]-a[pre]>=x&&l-a[crt]>=x)
		{
			ans++;
			pre=crt;
		}
		
	}
	if(ans>=n)
	return true;
	else
	return false;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator