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 1721493979 at 2018-10-12 09:51:19 on Problem 2018
#include<iostream>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<algorithm>

using namespace std;
double a[100001],b[100001],sum[100001];
 
int main()
{
	int N,L;
	cin>>N>>L;
	for(int i = 1; i <= N; i++) scanf("%lf",&a[i]); 
	double eps = 1e-5;
	double l = -1e6, r = 1e6;
	while(r - l > eps)
	{ 
		double mid = (l +r )/2;
		for(int i = 1; i <= N; i++) b[i] = a[i] - mid;
		for(int i = 1; i <= N; i++) 
			sum[i] = (sum[i - 1] + b[i]);
		double ans = -1e10;
		double min_val = 1e10;
		for(int i = 1; i <= N; i++){
			min_val = min(min_val,sum[i - L]);
			ans = max(ans,sum[i] - min_val);
		}
		if(ans >= 0) l = mid; else r = mid;
	}
	cout<<int (r * 1000)<<endl;
	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