hdu 4811 Ball

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?

InputThere 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.OutputFor 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

感觉自己归纳能力为0。
这是我的ac代码:
 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cmath>
 4 #include <string>
 5 #include <cstring>
 6 #include <algorithm>
 7 #include <iomanip>
 8 #include <map>
 9 using namespace std;
10 typedef long long ll;
11 map<string,double>mp;
12 ll nu[11];
13 int main() {
14     ll r,y,b;
15     ll sum=0;
16     ll ans=0;
17     while(cin>>nu[0]>>nu[1]>>nu[2])
18     {
19         ans=0;
20         sum=0;
21         sort(nu,nu+3);
22         r=nu[0];y=nu[1],b=nu[2];
23         sum=r+y+b;
24         if(r>=2)                        ans=6*sum-21;//cout<<6*sum-21<<endl;
25         else if(r==0 && y==0 && b<=1)   ans=0;//cout<<0<<endl;
26         else if(r==0 && y==0 && b>=2)   ans=2*sum-3;//cout<<2*sum-3<<endl;
27         else if(r==0 && y==1 && b==1)   ans=1;//cout<<1<<endl;
28         else if(r==0 && y==1 && b==2)   ans=3;//cout<<3<<endl;
29         else if(r==0 && y==1 && b>2)    ans=3*sum-6;//cout<<3*sum-6<<endl;
30         else if(r==0 && y>=2 && b>=2)   ans=4*sum-10;//cout<<4*sum-10<<endl;
31         else if(r==1 && y==1 && b==1)   ans=3;//cout<<3<<endl;
32         else if(r==1 && y==1 && b==2)   ans=6;//cout<<6<<endl;
33         else if(r==1 && y==1 && b>2)    ans=4*sum-10;//cout<<4*sum-10<<endl;
34         else if(r==1 && y>=2 && b>=2)   ans=5*sum-15;//cout<<5*sum-15<<endl;
35         cout<<ans<<endl;
36     }
37     return 0;
38 }
View Code

在推的过程中我已经感受到规律了,但就是不会归纳总结。

看了题解才明白,但感觉如果下次遇到类似的题我还是总结不出来啊。

附题解:http://blog.csdn.net/w446506278/article/details/51915485

题意:

有三种颜色,给你每种颜色的球的数量,有以下两种得分方式,问你如何放置这些球,让总得分最大。

方式一:放第一个球的得分为0

方式二:放在最后面的得分为之前的所有球的颜色种数

方式三:放在中间的得分为左边球的颜色种数+右边球的颜色种数

思路:

找规律,推导出公式,因为只有三种颜色,如果每种颜色都有2的及以上,那么可以先在两边各摆三种颜色的球,这样每次把其他球放入中间时都能得到6分,即ans=(R-2+Y-2+B-2)*6+15(15为在两边各摆三种颜色的球的过程所获得的总得分)。

若有颜色不到2个,则只是一开始两边摆的球的颜色数减少了一点,设此时两边的颜色总数和为a,那么后面每个加入的球放中间都能得到a分,即ans=(总的球数-先摆的球数)*a+b(b为先摆的过程中所获得的得分,b=(0+先摆的球数-1)*先摆的球数/2)。

 1 #include<cstdio>
 2 typedef __int64 LL;
 3 
 4 LL R,Y,B;
 5 
 6 int main(){
 7     while(~scanf("%I64d%I64d%I64d",&R,&Y,&B)){
 8         LL ans=0;
 9         LL RR=R>=2?2:R;
10         LL YY=Y>=2?2:Y;
11         LL BB=B>=2?2:B;
12         LL same=RR+YY+BB;
13         LL other=R+Y+B-same;
14         ans=((0+same-1)*same)/2;
15         ans+=other*same;
16         printf("%I64d
",ans);
17     }
18     return 0;
19 }
View Code
原文地址:https://www.cnblogs.com/zmin/p/8359022.html