Codeforces Beta Round #62
昨晚做了下比赛就早早地睡了,早上爬起来一看,才蛋疼地发现第二题忘记考虑除0的情况,加了一两行代码,一交就AC了,杯具~~~~~~
sum - ave*n = ( a[n] - ave)* k% + (a[n-1]-ave)*k% + (a[n-2]-ave)*k% + ... + (a[i]-ave)*k%
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <vector> #include <iterator> #include <queue> #include <cmath> using namespace std; typedef __int64 lld; int main() { // freopen("c:/aaa.txt", "r", stdin); double num[10005], sum[10005], k; double ave, maxx; int n, i; scanf( "%d %lf", &n, &k ); k /= 100; for( i=1; i<=n; ++i ) scanf( "%lf", &num[i] ); sort( num+1, num+n+1 ); sum[0] = 0; for( i=1; i<=n; ++i ) sum[i] = sum[i-1] + num[i]; if( k != 0 ) { maxx = num[1]; for( i=2; i<=n; ++i ) { ave = (sum[n]/k - (sum[n] - sum[i-1])) / (n/k-(n-i+1)); if( ave >= num[i-1] && ave <= num[i] ) { if( ave > maxx ) maxx = ave; } } } else { maxx = sum[n]/n; } printf( "%.9lf\n", maxx ); return 0; }