zoukankan      html  css  js  c++  java
  • Codeforces Round #273 (Div. 2)C. Table Decorations 数学

    C. Table Decorations
     

    You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color?

    Your task is to write a program that for given values rg and b will find the maximum number t of tables, that can be decorated in the required manner.

    Input

    The single line contains three integers rg and b (0 ≤ r, g, b ≤ 2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.

    Output

    Print a single integer t — the maximum number of tables that can be decorated in the required manner.

    Sample test(s)
    input
    5 4 3
    output
    4
     
    Note

    In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively.

     题意:给你三种颜色的气球, 现在让你从中选出三个,满足:最多有两个气球的颜色是一样的。问你这样满足条件的方案数

    题解:   我们来对三种气球的数量排序,从大到小a,b,c,  

              如果a/2>=b+c显然最多就是b+c;画个图,就知道了

             那么就只有  (a+b+c)/3这种解了

    ///1085422276
    #include<bits/stdc++.h>
    using namespace std ;
    typedef long long ll;
    #define mem(a) memset(a,0,sizeof(a))
    #define meminf(a) memset(a,127,sizeof(a));
    #define inf 1000000007
    #define mod 1000000007
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){
            if(ch=='-')f=-1;ch=getchar();
        }
        while(ch>='0'&&ch<='9'){
            x=x*10+ch-'0';ch=getchar();
        }return x*f;
    }
    //************************************************
    const int maxn=20000+5;
    ll c[maxn];
    ll ans;
    int main(){
    
    
        for(int i=1;i<=3;i++){
            scanf("%I64d",&c[i]);
        }
        sort(c+1,c+3+1);
        if(c[1]+c[2]<=c[3]/2){
           ans=c[1]+c[2];
        }
        else if(c[1]+c[2]<=c[3]) {
               ans=(c[1]+c[2]+c[3])/3;
        }
        else if(c[1]+c[2]>c[3]){
            ans=(c[1]+c[2]+c[3])/3;
        }
        cout<<ans<<endl;
      return 0;
    }
    代码
  • 相关阅读:
    CNN comprehension
    Gradient Descent
    Various Optimization Algorithms For Training Neural Network
    gerrit workflow
    jenkins job配置脚本化
    Jenkins pipeline jobs隐式传参
    make words counter for image with the help of paddlehub model
    make words counter for image with the help of paddlehub model
    git push and gerrit code review
    image similarity
  • 原文地址:https://www.cnblogs.com/zxhl/p/4926058.html
Copyright © 2011-2022 走看看