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

大牛们过来看看啦,该注意的地方都注意了,为何还是WA呢?

Posted by xtu716 at 2007-09-06 09:03:12 on Problem 3232
#include <stdio.h>
int end[100005];

void main()
{
	int T,i,n;
	scanf("%d",&T);
	while(T--)
	{
		int yi,M,K;
		__int64 out;
		int min,left=0,right=100000000;
		scanf("%d",&n);
		for(i=0;i<n;i++)
			scanf("%d",&end[i]);
		scanf("%d %d",&M,&K);

		if(K==1)
		{
			right=-1;
			for(i=0;i<n;i++)
				if(right<end[i])right=end[i];
		}
		else
		{			
			while(left<right)
			{
				int sg=0;
				min=(left+right)/2;
				out=M*min;
				if(M>n)out=n*min;
				for(i=0;i<n;i++)
				{
					if(end[i]>min)
					{
						yi=(end[i]-min+K-2)/(K-1);//向后推进K+2个位置,化解了有余数的情况
						out-=(__int64)yi;
						if(yi>min)sg=1;
					}
				}
				if(out<0||sg==1)left=min+1;
				else right=min;
			}
		}
		printf("%d\n",right);
	}
}


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