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

求解哪错了!!discuss里的所有变态数据都过了!!就是WA!

Posted by sdfzyhx at 2016-02-17 19:44:27 on Problem 2018
#include<cstdio>
#include<cstring>
int a[100010],n,f;
bool att(int x)
{
	int b[100010],q[100010],i,j,k,hd=1,tl=1;
	memset(b,0,sizeof(b));
	memset(q,0,sizeof(q));
	for (i=1;i<=n;i++)
	  b[i]=b[i-1]+a[i]-x;
	for (i=1;i<=n;i++)
	{
		while (i-q[hd+1]>=f&&hd<tl) hd++;
		if (b[i]<b[q[tl]]) q[++tl]=i;
		else 
		  if (i-q[hd]>=f&&b[i]-b[q[hd]]>=0) return 1;
	}
	return 0;
}
int main()
{
	int i,j,k,l,p,q,x,y,z,max,min,r;
	scanf("%d%d",&n,&f);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		a[i]*=1000;
	}
	max=-1;
	min=10000000;
	for (i=1;i<=n;i++)
	{
		if (a[i]>max) max=a[i];
		if (a[i]<min) min=a[i];
	}
	l=min;
	r=max;
	while (l<r)
	{
		if (att((l+r)/2+1)) l=(l+r)/2+1;
		else r=(l+r)/2;
	}
	printf("%d\n",l);
}

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