zoukankan      html  css  js  c++  java
  • hdu-4811 Ball

    题目链接:

    Ball

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 2149    Accepted Submission(s): 897


    Problem Description
    Jenny likes balls. He has some balls and he wants to arrange them in a row on the table.
    Each of those balls can be one of three possible colors: red, yellow, or blue. More precisely, Jenny has R red balls, Y yellow balls and B blue balls. He may put these balls in any order on the table, one after another. Each time Jenny places a new ball on the table, he may insert it somewhere in the middle (or at one end) of the already-placed row of balls.
    Additionally, each time Jenny places a ball on the table, he scores some points (possibly zero). The number of points is calculated as follows:
    1.For the first ball being placed on the table, he scores 0 point.
    2.If he places the ball at one end of the row, the number of points he scores equals to the number of different colors of the already-placed balls (i.e. expect the current one) on the table.
    3.If he places the ball between two balls, the number of points he scores equals to the number of different colors of the balls before the currently placed ball, plus the number of different colors of the balls after the current one.
    What's the maximal total number of points that Jenny can earn by placing the balls on the table?
     
    Input
    There are several test cases, please process till EOF.
    Each test case contains only one line with 3 integers R, Y and B, separated by single spaces. All numbers in input are non-negative and won't exceed 109.
     
    Output
    For each test case, print the answer in one line.
     
    Sample Input
    2 2 2 3 3 3 4 4 4
     
    Sample Output
    15 33 51
     
    题意:
     
    给出三种球的个数,然后再求题目要求的那个最大值;
     
    思路:
     
    分情况讨论啦,比如现在现在三种球的个数都大于2,那么在放球的话就可以最大得到6的分数了,然后其他的情况也是这样啦;
     
    AC代码:
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int maxn=1e5+10;
    int n,m,k;
    int main()
    {
        while(scanf("%d%d%d",&n,&m,&k)!=EOF)
        {
            if(n>=2&&m>=2&&k>=2)
            {
                LL ans=n-2+m-2+k-2;
                printf("%lld
    ",ans*6+15);
            }
            else 
            {
                int a[4];
                a[0]=n,a[1]=m,a[2]=k;
                sort(a,a+3);
                int num=0;
                for(int i=0;i<3;i++)if(a[i]==0)num++;
                if(num==3)printf("0
    ");
                else if(num==2)
                {
                    if(a[2]==1)printf("0
    ");
                    else printf("%d
    ",a[2]*2-3);
                }
                else if(num==1)
                {
                    if(a[2]==1)printf("1
    ");
                    else 
                    {
                        if(a[1]==1)
                        {
                            if(a[2]==1)printf("1
    ");
                            else 
                            {
                                LL ans=a[2]-2;
                                printf("%lld
    ",3*ans+3);
                            }
                        }
                        else 
                        {
                            LL ans=a[1]-2+a[2]-2;
                            printf("%lld
    ",ans*4+6);
                        }
                    }
                }
                else 
                {
                    if(a[2]==1)printf("3
    ");
                    else 
                    {
                        if(a[1]==1)
                        {
                                LL ans=a[2]-2;
                                printf("%lld
    ",6+ans*4);
                        }
                        else 
                        {
                                LL ans=a[1]-2+a[2]-2;
                                printf("%lld
    ",5*ans+10);
                        }
                    }
                }
            }
        }
    
        return 0;
    }
    

      

     
  • 相关阅读:
    偶遇this之坑
    程序员的职业素养——读后感
    我怎么没想到——读后感
    黑客与画家——读后感
    漫谈认证与授权
    动手造轮子:实现一个简单的依赖注入(二) --- 服务注册优化
    动手造轮子:实现简单的 EventQueue
    asp.net core 自定义 Policy 替换 AllowAnonymous 的行为
    SQL Server 中 `JSON_MODIFY` 的使用
    WeihanLi.Npoi 近期更新
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5926647.html
Copyright © 2011-2022 走看看