Ball HDU - 4811

Posted Fitz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ball HDU - 4811相关的知识,希望对你有一定的参考价值。

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,依次放球,放在两端的时候所加的分数为之前球颜色的种类,
把球放在中间时所加的分数为这个放的球的两边的球的颜色的种类。
    求出放完球最后的分数为多少?
这题做的方法特别多,我第一次做的时候想不出简单的方法,然后就是不断枚举,找到其中的规律。
下面放出我第一次做的代码,相信读者很容易看出其中的规律
 
 1 #include "cstdio"
 2 #include "cstring"
 3 #include <math.h>
 4 #include "cstdlib"
 5 #include "iostream"
 6 #include<algorithm>
 7 using namespace std;
 8 
 9 int main() {
10     long long a[5];
11     long long sum;
12     while(scanf("%lld%lld%lld",&a[0],&a[1],&a[2])!=EOF){
13         sort(a,a+3);
14         sum=0;
15         if (a[0]>=2 && a[1]>=2 && a[2]>=2) sum=15+((a[0]+a[1]+a[2])-6)*6;
16         else if (a[0]==0 && a[1]==0 && a[2]==0) sum=0;
17         else if (a[0]==0 && a[1]==0 && a[2]==1) sum=0;
18         else if (a[0]==0 && a[1]==0 && a[2]>=2)  sum=1+(a[2]-2)*2;
19         else if (a[0]==0 && a[1]==1 && a[2]==1) sum=1;
20         else if (a[0]==0 && a[1]==1 && a[2]>=2)  sum=3+(a[2]-2)*3;
21         else if (a[0]==1 && a[1]==1 && a[2]==1) sum=3;
22         else if (a[0]==1 && a[1]==1 && a[2]>=2)  sum=6+(a[2]-2)*4;
23         else if (a[0]==0 && a[1]>=2  && a[2]>=2)  sum=6+(a[2]+a[1]-4)*4;
24         else if (a[0]==1 && a[1]>=2 && a[2]>=2)   sum=10+(a[2]+a[1]-4)*5;
25         printf("%lld\n",sum);
26         memset(a,0,sizeof(a));
27     }
28     return 0;
29 }

 


以上的方法是纯粹的暴力 个人感觉是非常蠢的。
下面的代码简短,就是以上代码的概括


 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 6 #include<queue>
 7 using namespace std;
 8 long long get(long long  x)
 9 {
10     if (x>=2) return 2;
11     else return x;
12 }
13 int main() {
14     long long a,b,c;
15     while(scanf("%lld%lld%lld",&a,&b,&c)!=EOF){
16         long long x=get(a)+get(b)+get(c);
17         long long y=a+b+c-x;
18         long long z=y*x+(x-1)*x/2;
19         printf("%lld\n",z);
20     }
21     return 0;
22 }

 

以上是关于Ball HDU - 4811的主要内容,如果未能解决你的问题,请参考以下文章

Ball HDU - 4811

hdu1556-Color the ball

B - Color the ball (HDU - 1556)

HDU 4362 Dragon Ball 贪心DP

HDU 5821 Ball (贪心)

HDU 2277 Change the ball