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

简单易懂系列

Posted by liu_cheng_ao at 2016-10-07 11:42:18 on Problem 2456
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;
int n,c,x[110000];
bool Isable(int d)
{
	int cnt=1,t=x[1];
	for(int i=2;i<=n;i++)
	if(x[i]-t>=d)
	{
		t=x[i];cnt++;
		if(cnt>=c)return true;
	}
	return false;
}
int main()
{
	scanf("%d%d",&n,&c);
	for(int i=1;i<=n;i++)
	scanf("%d",&x[i]);
	sort(x+1,x+n+1);
	int l=1,r=x[n]-x[1];
	while(l!=r)
	{
		int m=(l+r+1)>>1;
		if(Isable(m))l=m;else r=m-1;
	}
	printf("%d",l);
	return 0;
}

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