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 }

原文地址:https://www.cnblogs.com/qldabiaoge/p/8510779.html

时间: 2024-07-31 10:58:56

Ball HDU - 4811的相关文章

HDU 4811 Ball(贪心)

2014-05-15 22:02 by Jeff Li 前言 系列文章:[传送门] 马上快要期末考试了,为了学点什么.就准备这系列的博客,记录复习的成果. 正文-计数  概率 概率论研究随机事件.它源于赌徒的研究.即使是今天,概率论也常用于赌博.随机事件的结果是否只凭运气呢?高明的赌徒发现了赌博中的规律.尽管我无法预知事件的具体结果,但我可以了解每种结果出现的可能性.这是概率论的核心. "概率"到底是什么?这在数学上还有争议."频率派"认为概率是重复尝试多次,某种结

hdu 4811 Ball(数学)

题目链接:hdu 4811 Ball 题目大意:有三种颜色的球若干,每次向桌子上放一个球,保证是一条序列,每次放球的得分为当前放入序列的球的前面有多少种不同的颜色a,后面的有多少种不同的颜色b,a+b.问说给定球的数量后,最大得分为多少. 解题思路:因为放球顺序是自己定的,所以我们可以尽量早得构造一个序列,使得后面放入球的得分均保持在峰值.那么求峰值就要根据球的数量来决定.我们叫得分为峰值的求为最高得分球,它们有很多个.对于一种颜色来说:0个,表示不能为在最高得分球的左边和右边,换句话来说,就是

[思路] hdu 4811 Ball

题意: 有三种颜色的小球,每种颜色数量R,Y,B 依次把球放到桌面上成一个序列,每次得分为这个球前面有多少种不同颜色的球+后面有多少种不同颜色的球 问总得分的最大值 思路: 构造前面的球和后面的球先放好,剩下的就放中间了 代码: #include"cstdlib" #include"cstdio" #include"cstring" #include"cmath" #include"queue" #incl

hdu 4811 数学 不难

http://acm.hdu.edu.cn/showproblem.php?pid=4811 因为看到ball[0]>=2 && ball[1]>=2 && ball[2]>=2  ans=(sum-6)*6+15    sum是三种颜色的球个数的和,然后就想到分类讨论,因为情况是可枚举的, 发现整数如果不加LL直接用%I64d打印会出问题 //#pragma comment(linker, "/STACK:102400000,102400000

树状数组模板--Color the ball

Color the ball HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色.但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗? Input 每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a b(1 <= a <= b <

2013nanjingJ

J - Ball Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4811 Appoint description:  System Crawler  (2014-10-08) Description Jenny likes balls. He has some balls and he wants to arrange them in

树状数组(区间更新,单点查询)

G - Color the ball HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色.但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗? Input每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a b(1 <= a <= b &

线段树(求单结点) hdu 1556 Color the ball

Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 22122    Accepted Submission(s): 10715 Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"

HDU 2277 Change the ball

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2277 Change the ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 694    Accepted Submission(s): 272 Problem Description Garfield has three pile