HDU 4811-Ball

怼烎@ 2022-02-23 03:38 309阅读 0赞

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

代码:

  1. /*
  2. */
  3. #include<map>
  4. #include<set>
  5. #include <vector>
  6. #include<stack>
  7. #include<queue>
  8. #include<cmath>
  9. #include<string>
  10. #include<cstdio>
  11. #include<cstring>
  12. #include<cstdlib>
  13. #include<iostream>
  14. #include<algorithm>
  15. using namespace std;
  16. #define ll unsigned long long
  17. #define inf 0x3f3f3f
  18. #define esp 1e-8
  19. #define bug {printf("mmp\n");}
  20. #define mm(a,b) memset(a,b,sizeof(a))
  21. #define T() int test,q=1;scanf("%d",&test); while(test--)
  22. const int maxn=1e6+10;
  23. const double pi=acos(-1.0);
  24. const int N=201;
  25. const int mod=1e9+7;
  26. int main()
  27. {
  28. ll r,y,b;
  29. while(scanf("%lld%lld%lld",&r,&y,&b)!=EOF)
  30. {
  31. ll x=0;
  32. if(r>2)
  33. {
  34. x+=r-2;
  35. r=2;
  36. }
  37. if(y>2)
  38. {
  39. x+=y-2;
  40. y=2;
  41. }
  42. if(b>2)
  43. {
  44. x+=b-2;
  45. b=2;
  46. }
  47. ll sum=r+y+b;
  48. ll ans1=0,y=0;
  49. if(sum==0)
  50. {
  51. ans1=0;
  52. y=0;
  53. }
  54. else if(sum==1)
  55. {
  56. ans1=0;y=0;
  57. }
  58. else if(sum==2)
  59. {
  60. ans1=1;
  61. y=2;
  62. }
  63. else if(sum==3)
  64. {
  65. ans1=3;
  66. y=3;
  67. }
  68. else if(sum==4)
  69. {
  70. ans1=6;
  71. y=4;
  72. }
  73. else if(sum==5)
  74. {
  75. ans1=10;
  76. y=5;
  77. }
  78. else if(sum==6)
  79. {
  80. ans1=15;
  81. y=6;
  82. }
  83. ans1+=x*y;
  84. printf("%lld\n",ans1);
  85. }
  86. return 0;
  87. }

发表评论

表情:
评论列表 (有 0 条评论,309人围观)

还没有评论,来说两句吧...

相关阅读