HDU 4811(思维题)

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 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,分别代表红球数量,黄球数量,蓝球数量,然后每次放一个球,这个球的得分为这个球左边的球的种类+这个球右边球的种类,然后让你求把全部的球放完后的最大的总得分
思路:假设黄球的数量为0,那么其它球放入后,黄球不能够为其他球创造得分,如果黄球数量为1那么黄球放到任意1边就能够为其它颜色的球创造1的得分,如果黄球的数量为2,那么黄球放到两边,其他球放到两个黄球中间,黄球就能够为其它的球创造2分,如果黄球的数量大于2的话其实是和2的效果一样的,最多能创造2分,能想到这里然后就好办了。首先算出来所有球创造的最大得分之和(g),然后每次放1个球,价值从0开始,每次价值加1,直到达到最大可以创造的得分(g),然后算一下剩余的球的个数(h-g),剩余的球只要放就是最大得分,剩余的球创造的得分为(h-g)*g,然后加上之前的球的得分就是答案

#include
#include
#include
#define ll long long
using namespace std;
ll uuu(ll u)
{
    if(u<=2)
    {
        return u;
    }
    return 2;
}
int main()
{
    ll r,y,b;
    while(scanf("%lld%lld%lld",&r,&y,&b)!=EOF)
    {
        ll g=uuu(r)+uuu(y)+uuu(b);//最大得分
        ll h=r+y+b;  //所有球的个数
        ll sum=0;
        for(ll i=0;i<g;i++)
        {
            sum+=i;  //在没达到最大得分之前的球的得分之和
        }
        if(h>g)
        {
            sum+=(h-g)*g;
        }
        printf("%lld\n",sum);
    }
    return 0;
}

你可能感兴趣的:(#,【思维题】)