首页 > 代码库 > hdu-4811 Ball
hdu-4811 Ball
题目链接:
Ball
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2149 Accepted Submission(s): 897
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?
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.
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 23 3 34 4 4
Sample Output
153351
题意:
给出三种球的个数,然后再求题目要求的那个最大值;
思路:
分情况讨论啦,比如现在现在三种球的个数都大于2,那么在放球的话就可以最大得到6的分数了,然后其他的情况也是这样啦;
AC代码:
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int maxn=1e5+10;int n,m,k;int main(){ while(scanf("%d%d%d",&n,&m,&k)!=EOF) { if(n>=2&&m>=2&&k>=2) { LL ans=n-2+m-2+k-2; printf("%lld\n",ans*6+15); } else { int a[4]; a[0]=n,a[1]=m,a[2]=k; sort(a,a+3); int num=0; for(int i=0;i<3;i++)if(a[i]==0)num++; if(num==3)printf("0\n"); else if(num==2) { if(a[2]==1)printf("0\n"); else printf("%d\n",a[2]*2-3); } else if(num==1) { if(a[2]==1)printf("1\n"); else { if(a[1]==1) { if(a[2]==1)printf("1\n"); else { LL ans=a[2]-2; printf("%lld\n",3*ans+3); } } else { LL ans=a[1]-2+a[2]-2; printf("%lld\n",ans*4+6); } } } else { if(a[2]==1)printf("3\n"); else { if(a[1]==1) { LL ans=a[2]-2; printf("%lld\n",6+ans*4); } else { LL ans=a[1]-2+a[2]-2; printf("%lld\n",5*ans+10); } } } } } return 0;}
hdu-4811 Ball
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。