Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:这个是错的,比如对这个数据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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator