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

Re:这个是错的,比如对这个数据

Posted by weihaohaoren at 2012-05-13 18:34:21 on Problem 2018
In Reply To:这个是错的,比如对这个数据 Posted by:updog at 2011-06-13 09:26:38
我的AC程序也是错的 用的是O(N)的方法
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
int n,f;
int a[100001];
int b[100001];
int main()
{
	//freopen("input.txt","r",stdin);
	scanf("%d%d",&n,&f);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	for(int i=1;i<=n;i++) b[i]=a[i]+b[i-1];
	int sum=0;
	for(int i=1;i<=f;i++) sum+=a[i];
	int cur=f;
	double ave=1.0*sum/f;
	for(int i=f+1;i<=n;i++)
	{
		sum+=a[i];
		cur++;
		int tsum=b[i]-b[i-f];
		if(1.0*tsum/f>1.0*sum/cur)
		{
			sum=tsum;
			cur=f;
		}		
		ave=max(ave,1.0*sum/cur);
	}
	printf("%d\n",(int)(ave*1000));
	//fclose(stdin);
	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