HDU 4811-Ball

Ball

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


 

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

 

Source

2013ACM/ICPC亚洲区南京站现场赛——题目重现

 题目大意:给你红黄蓝三种颜色的球,现在通过放球得分:规则是,第一个球不得分,放在最后的球的得分是他前面的球的颜色的种类和,第三种,是在两个球之间插一个球,它的得分是,它前面的颜色种类和和它后面的颜色种类和。问你他能得到分数最大是多少。

思路:如果球的数量足够(每种都不少于2个),从第一个开始放置的时候,依次增加的分数为,0,1,2,3,4,5,6,6,6,6……,如果某一个颜色的球只有一个则,0,1,2,3,4,5,5,5……,依次类推……于是只要知道最后固定增长的数字的值,就很容易计算出来了。

特别说明:要注意用long long

代码:

/*

*/
#include<map>
#include<set>
#include <vector>
#include<stack>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll unsigned long long
#define inf 0x3f3f3f
#define esp 1e-8
#define bug {printf("mmp\n");}
#define mm(a,b) memset(a,b,sizeof(a))
#define T() int test,q=1;scanf("%d",&test); while(test--)
const int maxn=1e6+10;
const double pi=acos(-1.0);
const int N=201;
const int mod=1e9+7;
int main()
{
    ll r,y,b;
    while(scanf("%lld%lld%lld",&r,&y,&b)!=EOF)
    {
        ll x=0;
        if(r>2)
        {
            x+=r-2;
            r=2;
        }
        if(y>2)
        {
            x+=y-2;
            y=2;
        }
        if(b>2)
        {
            x+=b-2;
            b=2;
        }
        ll sum=r+y+b;
        ll ans1=0,y=0;
        if(sum==0)
        {
            ans1=0;
            y=0;
        }
        else if(sum==1)
        {
            ans1=0;y=0;
        }
        else if(sum==2)
        {
            ans1=1;
            y=2;
        }
        else if(sum==3)
        {
            ans1=3;
            y=3;
        }
        else if(sum==4)
        {
            ans1=6;
            y=4;
        }
        else if(sum==5)
        {
            ans1=10;
            y=5;
        }
        else if(sum==6)
        {
            ans1=15;
            y=6;
        }
        ans1+=x*y;
        printf("%lld\n",ans1);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/lee371042/article/details/89055292
今日推荐