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 13408100238 at 2014-08-21 11:16:28 on Problem 2456
#include"iostream"
#include"cstdio"
#include"cstring"
#include"algorithm"
using namespace std;
const int inf=0x7fffffff;
const int ms=100004;
int d[ms];
int N,C;
bool judge(int dis)
{
	int last=0;
	for(int i=1;i<C;i++)
	{
		int tmp=last+1;
		while(tmp<N&&d[tmp]<(d[last]+dis))
			tmp++;
		if(tmp==N)
			return false;
		last=tmp;
	}
	return true;
}
void solve()
{
	sort(d,d+N);
	int begin=0,end=inf;
	while(end-begin>1)
	{
		int mid=(begin+end)/2;
		if(judge(mid))
			begin=mid;
		else
			end=mid;
	}
	printf("%d\n",begin);
	return ;
}
int main()
{
	scanf("%d%d",&N,&C);
	for(int i=0;i<N;i++)
		scanf("%d",&d[i]);
	solve();
	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