ball

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 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

题目大意:有三种颜色的球若干,每次向桌子上放一个球,保证是一条序列,每次放球的得分为当前放入序列的球的前面有多少种不同的颜色a,后面的有多少种不同的颜色b,a+b。问说给定球的数量后,最大得分为多少。

解题思路:因为放球顺序是自己定的,所以我们可以尽量早得构造一个序列,使得后面放入球的得分均保持在峰值。那么求峰值就要根据球的数量来决定。我们叫得分为峰值的求为最高得分球,它们有很多个。对于一种颜色来说:0个,表示不能为在最高得分球的左边和右边,换句话来说,就是不能创造得分;1个,要么在左要么在右,创造一个得分;2个左右各一,创造两个得分;2个以上,一边有两个没有意义,所以还是两个得分。 于是峰值即被求出来了,剩下的就简单多了。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
ll cmp(ll i){
	if(i<=2)
	return i;
	else 
	return 2; 
}
int main(){
	ll n,m,k;
	while(cin >> n >> m >> k){
		ll r1=cmp(n)+cmp(m)+cmp(k);
		ll r2=n+m+k;
		ll sum=0;
		for(int i=0;i<r2&&i<r1;i++){
			sum+=i;
		}
		if(r2>r1)
		sum+=(r2-r1)*r1;
		cout << sum << endl;
	}
	return 0;
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值