Codeforces 557B Pasha and Tea 倒茶

题意:Pasha有2n个茶杯,每个茶杯的容积不同。Pasha有2n个朋友,男女各n个。现在Pasha要将总容积为w的茶倒在2n个茶杯里,分给这2n个朋友,并规定同性别的朋友茶杯中的茶容积相同,且每个男性朋友茶杯中茶的容积是每个女性朋友茶杯中茶的容积的两倍。求所有朋友茶杯中的茶容积之和的最大值。

水题。首先按照茶杯的容积排序,较小的n个茶杯肯定是分给了女生,较大的n个茶杯分给男生。若不然,如果某个男性朋友茶杯容积比某个女性朋友茶杯容积小的话,由于男性朋友茶杯中茶的容积较大,那么互换他们的茶杯,仍然可以装得下各自原来的茶。所以这样看来这种分法一定可以。那么既然每个同性朋友的茶一样多,我们只需考虑男性朋友中茶杯容积最小的和女性朋友中茶杯容积最小的即可。设女性朋友中茶杯容积最小的为x,男性朋友总茶杯容积最小的为y,由于总茶量只有w,故最后的答案为min(min(2x,y)*1.5*n,w)。

#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <stack>#include <queue>#include <vector>#include <map>#include <set>using namespace std;const int MAX = 100005;int n;double w, a[2*MAX];void input(){for(int i = 0; i < 2*n; i++)scanf("%lf", &a[i]);}void solve(){sort(a, a + 2*n);printf("%.6lf\n", min(min(2*a[0], a[n])*1.5*n, w));}int main(){while(scanf("%d%lf", &n, &w) != EOF){input();solve();}return 0;}

版权声明:本文为博主原创文章,,未经博主允许不得转载。

那段岁月,无论从何种角度读你,你都完美无缺,

Codeforces 557B Pasha and Tea 倒茶

相关文章:

你感兴趣的文章:

标签云: