Codeforces Round #311 (Div. 2) B. Pasha and Tea

【题目链接】click here~~

【题目大意】给你n个boy,n个girl ,然后W表示茶壶的最大容量,然后n个茶杯,每个都有不同的容量,要求boy的茶杯里的茶水是girl的两倍,且boy和boy容量一样,girl和girl 容量一样,问如何倒茶,最大化总的茶量

【解题思路】这道题本来很简单,第一次读题没读明白,以为每个茶杯的茶水都倒满了,然后一想不就是拿最大的计算吗。一交,直接WA,然后仔细读题,发现,每个茶杯的茶水可以选择的倒(坑~啊),那么既然boy和boy,girl和girl的茶水一样,那么只要分别找出最小的容量然后比较一下就可以,因为要求boy的茶杯里的茶水是girl的两倍,所以girl 的是最小的

代码:

#include <bits/stdc++.h>
using namespace std;
const int N=3*1e5+10;
double num[N];
int main()
{
    int n,w;
    while(scanf("%d%d",&n,&w)!=EOF)
    {
        for(int i=1; i<=2*n; ++i) scanf("%lf",&num[i]);
        sort(num+1,num+1+2*n);
        double res=min(num[1],num[n+1]/2);///排序玩后依次选择最小的
        res=res*3*n;
        res=min(res,1.0*w);
        printf("%.6f\n",res);
    }
    return 0;
}

res=res*3*n=res*n+res*2*n;

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

时间: 2024-08-03 15:12:34

Codeforces Round #311 (Div. 2) B. Pasha and Tea的相关文章

Codeforces Round #249 (Div. 2) B. Pasha Maximizes

看到题目的时候,以为类似插入排序,比较第i个元素和第i-1个元素, 如果第i个元素比第i-1个元素小,则不交换 如果第i个元素比第i-1个元素大,则交换第i个元素和第i-1个元素 继续比较第i-1个元素与前一个元素,直到前一个元素大为止 交换元素次大于等于k则停止 但对测试用例 1234 3 则出现问题,如果按照上述方法得到答案为3214, 但正确答案是4321,直接将第4个元素往前交换 故在上面基础上改进得 当扫描第i个元素时,则要取出[i,i+k+1)之间的最大元素,然后将最大元素往前交换,

Codeforces Round #311 (Div. 2) A,B,C,D,E

A. Ilya and Diplomas 思路:水题了, 随随便便枚举一下,分情况讨论一下就OK了. code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm> #include <iostream> #include <cstring> #include <cmath> #define inf 1000000

2017-4-25-Train:Codeforces Round #311 (Div. 2)

A. Ilya and Diplomas(贪心) Soon a school Olympiad in Informatics will be held in Berland, n schoolchildren will participate there. At a meeting of the jury of the Olympiad it was decided that each of the n participants, depending on the results, will g

Codeforces Round #297 (Div. 2)B Pasha and String

B. Pasha and String time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the

Codeforces Round #288 (Div. 2) A. Pasha and Pixels

A. Pasha and Pixels time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to

Codeforces Round #311 (Div. 2)

D 分4种情况讨论 1 不需要加边 , 就是说原本就有一个奇数环,我们只要跑一次二分图就好了 2 加一条边 , 也就是说存在大于等于3个点的联通块 我们对于这个联通块也跑一遍二分图, 可以知道图中所有的 同颜色染色中的点任意相连,都是一个奇数环,那么对于每个联通分量都有相应的数可以计算 3 加两条边,也就是说没有大于两个点的联通块存在,并且有两个点的联通块存在,答案也是可以计算出来的 e*(n-2) 4 加三条边 那么就可以知道每个联通块只有一个点,答案是 n*(n-1)*(n-2)/6; #i

Codeforces Round #311 (Div. 2) E. Ann and Half-Palindrome (DP+字典树)

题目地址:传送门 先用dp求出所有的符合要求的半回文串,标记出来.然后构造字典树.然后再dfs一遍求出所有节点的子树和,最后搜一遍就能找出第k个来了. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map>

Codeforces Round #311 (Div. 2)--D(图

题意:给出一个图,问最少加多少条边能连出一个奇圈,还要求输出连边的方法种数. 思路:比赛的时候看了一下是图相关的就没多想,也没时间了,其实挺简单的,如果已经有奇圈,那么直接输出0 1,如果最多有两个点相连,那么就是(n-2)×m,就是每条边和另外的任意点连两条边,要么就是没有边,这个就是直接输出结果.. 稍微麻烦一点的是最后一种,联通块有多个点且没有奇圈,这时候需要把联通快黑白染色,同色的点相连就是一个奇圈,dfs的时候统计每个联通块中两种=颜色的个数即可. #include<bits/stdc

Codeforces Round #311 (Div. 2)A Ilya and Diplomas

[比赛链接]click here~~ [题目大意] n个人,获取一到三等文凭,每门文凭有大小范围,求最后文凭各颁发多少 [解题思路]直接枚举了, 看完题,赶紧写了一发代码,发现居然错过注册时间,系统提示不能提交代码,真是醉了~~,以后还是得提前注册: A题,比较简单: 代码: #include <iostream> #include <bits/stdc++.h> using namespace std; int main() { int n,m; int a1,a2; int b