codeforces #311 B B. Pasha and Tea(贪心)

来源:互联网 发布:淘宝网cf 编辑:程序博客网 时间:2024/05/16 18:23

题目链接:

点击打开链接

题目大意:

给出一个壶,能装w升水,给你2*n个杯子,每个杯子有自己的容量,然后n个杯子给女生加x升水,n个杯子给男生加2*x升水,问x最大的方案需要多少水

题目分析:

首先(x+2*x)*n = w ,求出一个上限

然后对杯子进行排序,a[n]/2提供一个上限

a[1]提供一个下限

然后判断一下就能得到结果,水题一枚。。。。

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define MAX 100007using namespace std;int a[MAX*3];int w,n;int main ( ){    while ( ~scanf ( "%d%d" , &n , &w ) )    {        double x = w*1.0/(3*n);        for ( int i = 0 ; i <2*n ; i++ )            scanf ( "%d" , &a[i] );        sort ( a , a+2*n );        double y = a[n]*1.0/2.0;        y = min ( y , (double)a[0] );        if ( x > y )           printf ( "%.8lf\n" , y*3*n );         else printf ( "%.8lf\n" , (double)w );    }}


0 0
原创粉丝点击