zoukankan      html  css  js  c++  java
  • JZOI1169A 平均数Ave

    #include <cstdio>
    #include <cmath>
    #define lztin() read()
    #define ztyout( a ) printf( "%.4lf", a )
    #define eps 1e-5
    #define ll long long
    using namespace std;
    inline int read() {
    	int x = 0,tmp = 1;char ch = getchar();
    	while( ch < '0' || ch > '9' ) {if ( ch == '-' ) tmp = -1; ch = getchar();}
    	while( ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar(); }
    	return x * tmp;
    }
    int A[110000], N, K, cnt;
    double B[1100000], T[1100000];
    double ans;
    void msort( int l, int r ) {
    	if( l == r ) return;
    	int mid = l + r >> 1;
    	msort( l, mid ); 
    	msort( mid + 1, r );
    	int i = l, k = l, j = mid + 1;
    	while( i <= mid && j <= r ) {
    		if( B[i] > B[j] ) {
    			cnt += mid - i + 1;
    			T[k] = B[j];
    			k ++, j ++;
    		} else {
    			T[k] = B[i];
    			k ++, i ++;
    		}
    	}
    	while( i <= mid ) {
    		T[k] = B[i];
    		k ++, i ++;
    	}
    	while( j <= r ) {
    		T[k] = B[j];
    		k ++, j ++;
    	}
    	for( int w = l ; w <= r ; ++ w ) B[w] = T[w];
    }
    int check( double mid ) {
    	B[0] = 0; cnt = 0;
    	for( int i = 1 ; i <= N ; ++ i ) {
    		B[i] = B[i - 1] + (double)A[i] - mid;
    	}
    	msort( 1, N );
    	for( int i = 1 ; i <= N ; ++ i )
    		cnt += ( B[i] < 0 );
    	return ( cnt >= K );
    }
    int main() {
    	N = lztin(), K = lztin();
    	for( int i = 1 ; i <= N ; ++ i ) {
    		A[i] = lztin();
    	}
    	double l = 0, r = (double)1e9, mid;
    	while( fabs( l - r ) > eps ) {
    		mid = ( l + r ) / 2.0;
    		if( check( mid ) ) ans = mid, r = mid;
    		else l = mid;
    	}
    	ztyout( ans );
    	
    	return 0;
    }
    
  • 相关阅读:
    线程与进程
    进程间通信之信号量与信号灯
    进程间通信之消息队列
    进程间通信之共享内存
    进程间通信之信号
    进程间通信之管道
    软件需求分析
    团队介绍
    EF Core(1.DBFirst)
    7.基本方式调用Api(http api)
  • 原文地址:https://www.cnblogs.com/ARZhu-NOIpAK/p/6862039.html
Copyright © 2011-2022 走看看