首页 > 代码库 > 2013nanjingJ
2013nanjingJ
J - Ball
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uAppoint description:
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 10 9.
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.
Output
For each test case, print the answer in one line.
Sample Input
2 2 23 3 34 4 4
Sample Output
153351
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #include<vector> 7 #define M(a,b) memset(a,b,sizeof(a)) 8 #include<map> 9 using namespace std;10 11 long long R,Y,B;12 13 int main()14 {15 while(scanf("%I64d%I64d%I64d",&R,&Y,&B)==3)16 {17 long long ans = 0;18 if(R>=2&&Y>=2&&B>=2) //全大于119 ans = (R+Y+B-6)*6+15;20 else21 {22 if(R==1&&Y>1&&B>1||Y==1&&R>1&&B>1||B==1&&Y>1&&R>1) //一个1其余大于123 {24 ans = (R+Y+B-5)*5+10;25 }26 else if(R==1&&Y==1&&B>1||B==1&&Y==1&&R>1||R==1&&B==1&&Y>1) //两个1一个大于127 {28 ans = (R+Y+B-4)*4+6;29 }30 else if(R==1&&Y==1&&B==1) //3个131 {32 ans = 3;33 }34 else if(R==0&&Y>1&&B>1||B==0&&Y>1&&R>1||Y==0&&B>1&&R>1) //1个035 {36 ans = (R+Y+B-4)*4+6;37 }38 else if(R==0&&Y==0&&B>1||B==0&&Y==0&&R>1||R==0&&B==0&&Y>1)//2个039 {40 ans = (R+B+Y-2)*2+1;41 }42 else if(R==0&&Y==1&&B>1||R==1&&Y==0&&B>1||B==1&&Y==0&&R>1||B==0&&Y==1&&R>1||R==0&&B==1&&Y>1||B==0&&R==1&&Y>1) //1个0,1个143 {44 ans = (R+B+Y-3)*3+3;45 }46 else if(R==0&&Y==1&&B==1||B==0&&Y==1&&R==1||Y==0&&B==1&&R==1)//1个0,2个147 {48 ans = 1;49 }50 else ans = 0; //2个0,1个1,3个051 }52 printf("%I64d\n",ans);53 }54 return 0;55 }
2013nanjingJ
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。