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?
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?
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.
2 2 2 3 3 3 4 4 4
15 33 51
题意:
3种颜色的球,放成一列
1.对于第一个放在桌子上的球,他得分为0分。
2.如果他将球放在排的一端,他得分的点数等于已经放置的球的不同颜色的数量(即期望当前的球数)在桌子上。
3.如果他把球放在两个球之间,他得分的点数等于当前放置的球之前的球的不同颜色的数量,加上当前球之后的球的不同颜色的数量。
让你算最后得分最大值。
思路:
列举一些情况后,发现其中得分情况无非6种:
0 1
0 1 2...
0 1 2 3 ...
0 1 2 3 4...
0 1 2 3 4 5...
0 1 2 3 4 5 6...
...后的值是一行最后那个值
然后就要分情况讨论了
我们发现,当一个颜色的球数量大于2时,每一次他最多贡献2个得分,如果数量小于2,那么有几个就能贡献多少分。
然后以此为条件判断,注意long long就行了
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
long long a,b,c;
{
while(scanf("%lld%lld%lld",&a,&b,&c)!=-1)
{ long long d=a+b+c;
int ans=0;
long long sum=0;
if(a>=2&&b>=2&&c>=2)
sum=15+(d-6)*6;
else
{
if(a>=2)
{
ans+=2;
d-=2;
}
else
{
ans+=a;d-=a;
}
if(b>=2)
{
ans+=2;
d-=2;
}
else
{
ans+=b;d-=b;
}
if(c>=2)
{
ans+=2;
d-=2;
}
else
{
ans+=c;d-=c;
}
sum=(ans+1)*ans/2+(d-1)*ans;
}
printf("%lld\n",sum);
}
}
return 0;
}