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\n",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\n");
            else if(num==2)
            {
                if(a[2]==1)printf("0\n");
                else printf("%d\n",a[2]*2-3);
            }
            else if(num==1)
            {
                if(a[2]==1)printf("1\n");
                else
                {
                    if(a[1]==1)
                    {
                        if(a[2]==1)printf("1\n");
                        else
                        {
                            LL ans=a[2]-2;
                            printf("%lld\n",3*ans+3);
                        }
                    }
                    else
                    {
                        LL ans=a[1]-2+a[2]-2;
                        printf("%lld\n",ans*4+6);
                    }
                }
            }
            else
            {
                if(a[2]==1)printf("3\n");
                else
                {
                    if(a[1]==1)
                    {
                            LL ans=a[2]-2;
                            printf("%lld\n",6+ans*4);
                    }
                    else
                    {
                            LL ans=a[1]-2+a[2]-2;
                            printf("%lld\n",5*ans+10);
                    }
                }
            }
        }
    }

    return 0;
}

  

时间: 2024-08-08 21:14:17

hdu-4811 Ball的相关文章

HDU 4811 Ball(贪心)

2014-05-15 22:02 by Jeff Li 前言 系列文章:[传送门] 马上快要期末考试了,为了学点什么.就准备这系列的博客,记录复习的成果. 正文-计数  概率 概率论研究随机事件.它源于赌徒的研究.即使是今天,概率论也常用于赌博.随机事件的结果是否只凭运气呢?高明的赌徒发现了赌博中的规律.尽管我无法预知事件的具体结果,但我可以了解每种结果出现的可能性.这是概率论的核心. "概率"到底是什么?这在数学上还有争议."频率派"认为概率是重复尝试多次,某种结

hdu 4811 Ball(数学)

题目链接:hdu 4811 Ball 题目大意:有三种颜色的球若干,每次向桌子上放一个球,保证是一条序列,每次放球的得分为当前放入序列的球的前面有多少种不同的颜色a,后面的有多少种不同的颜色b,a+b.问说给定球的数量后,最大得分为多少. 解题思路:因为放球顺序是自己定的,所以我们可以尽量早得构造一个序列,使得后面放入球的得分均保持在峰值.那么求峰值就要根据球的数量来决定.我们叫得分为峰值的求为最高得分球,它们有很多个.对于一种颜色来说:0个,表示不能为在最高得分球的左边和右边,换句话来说,就是

[思路] hdu 4811 Ball

题意: 有三种颜色的小球,每种颜色数量R,Y,B 依次把球放到桌面上成一个序列,每次得分为这个球前面有多少种不同颜色的球+后面有多少种不同颜色的球 问总得分的最大值 思路: 构造前面的球和后面的球先放好,剩下的就放中间了 代码: #include"cstdlib" #include"cstdio" #include"cstring" #include"cmath" #include"queue" #incl

Ball HDU - 4811

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

hdu 4811 数学 不难

http://acm.hdu.edu.cn/showproblem.php?pid=4811 因为看到ball[0]>=2 && ball[1]>=2 && ball[2]>=2  ans=(sum-6)*6+15    sum是三种颜色的球个数的和,然后就想到分类讨论,因为情况是可枚举的, 发现整数如果不加LL直接用%I64d打印会出问题 //#pragma comment(linker, "/STACK:102400000,102400000

hdu 5821 Ball(2016 Multi-University Training Contest 8——贪心+排序)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5821 Ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 515    Accepted Submission(s): 309 Problem Description ZZX has a sequence of boxes numbe

hdu 5821 Ball (贪心)

Ball Description ZZX has a sequence of boxes numbered 1,2,...,n. Each box can contain at most one ball. You are given the initial configuration of the balls. For 1 \leq i \leq n, if the i-th box is empty then a[i]=0, otherwise the i-th box contains e

2013nanjingJ

J - Ball Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4811 Appoint description:  System Crawler  (2014-10-08) Description Jenny likes balls. He has some balls and he wants to arrange them in

线段树(求单结点) hdu 1556 Color the ball

Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 22122    Accepted Submission(s): 10715 Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"

HDU 2277 Change the ball

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2277 Change the ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 694    Accepted Submission(s): 272 Problem Description Garfield has three pile