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

不需要用long long

Posted by 1340502116 at 2016-07-17 15:56:30 on Problem 3104
#include <cstdio>
#include <algorithm>
#include <math.h>
using namespace std;
const int MAXN=100005;
int n,k;
int x[MAXN];
bool test(int t)
{
	int s=0;
	for(int i=0;i<n;i++)
	{
		if(x[i]<=t)	continue;
		s+=(int)ceil((x[i]-t)*1.0/(k-1));
		if(s>t)	return false;
	}
	return true;
}
void inline read(int &x)
{
	char ch=getchar();
	while(ch<'0'||ch>'9')	ch=getchar();
	x=0;
	while('0'<=ch&&ch<='9')
	{
		x*=10;
		x+=(ch-'0');
	}
}
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		int mx=0;
		for(int i=0;i<n;i++)		
		{
			scanf("%d",&x[i]);
			//read(x[i]);
			mx=max(mx,x[i]);
		}
		scanf("%d",&k);
		//read(k);
		if(k==1)
		{
			printf("%d\n",mx);
		}
		else
		{
			int l=0;
			int r=0x3f3f3f3f;
			while(r-l>1)
			{
				int mid=(l+r)>>1;
				if(test(mid))	r=mid;
				else l=mid;
			}
			printf("%d\n",r);
		}
	}
	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