-----hdu 4811 ball

本文探讨了一种球排列计分策略的问题,通过放置不同颜色的球来获得分数,旨在找到最优解以获得最高的总分。文章给出了具体的计分规则,并通过示例说明了如何根据球的数量来计算最大可能得分。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 10 9.
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
题意:给你r个红球,y个黄球,b个蓝球,每放一个球,如果放在一端,它所得到的分数是它有球的那一端中,球的颜色的种类;如果中间插入,它所得到的分数是它左边的球的颜色的种类+右边的球的颜色的种类;求最高得分;
思路:当每种颜色的球,各达到2个之后,每放一个球,其最大能加的分就是6分,如果每种颜色的球都达到了2个,那么最大得分就应该是:每种颜色的球各2个时,摆放得到的最大分数(15)+(r-2+y-2+b-2)*6;
当然还有其他情况,比如每种颜色的球都不超过两个,这时候手算一下枚举出来就行;也会有有的球个数超过了2,但是有的小于等于2,如y=7,r=2,b=1, 其实当放了2个红球,2个黄球,1个蓝球后,每再放一个球,所得达到的最大份就是固定的了;

#include <iostream>
#include<stdio.h>
#include <algorithm>
#include <math.h>
#include <string.h>

int main()
{
    long long r,y,b;
    while(~scanf("%lld%lld%lld",&r,&y,&b))
    {
        long long k=0;
        long long ans=0;
        if(r>2)
        {
            k+=r-2;
            r=2;
        }
        if(y>2)
        {
            k+=y-2;
            y=2;
        }
        if(b>2)
        {
            k+=b-2;
            b=2;
        }
         long long sum=0;
        sum=r+y+b;
        if(sum==0)
        {
            ans+=0;
            y=0;
        }
        if(sum==1)
        {
            ans+=0;
            y=0;
        }
        if(sum==2)
        {
            ans+=1;
            y=2;
        }
        if(sum==3)
        {
            ans+=3;
            y=3;
        }
        if(sum==4)
        {
            ans+=6;
            y=4;
        }
        if(sum==5)
        {
            ans+=10;
            y=5;
        }
        if(sum==6)
        {
            ans+=15;
            y=6;
        }
        ans+=k*y;
        printf("%lld\n",ans);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值