码迷,mamicode.com
首页 > 其他好文 > 详细

2013nanjingJ

时间:2014-10-11 00:12:14      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   os   ar   for   

J - Ball
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Appoint 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?
 

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.
 

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
 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) //全大于1
19         ans = (R+Y+B-6)*6+15;
20       else
21       {
22           if(R==1&&Y>1&&B>1||Y==1&&R>1&&B>1||B==1&&Y>1&&R>1) //一个1其余大于1
23           {
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一个大于1
27           {
28               ans = (R+Y+B-4)*4+6;
29           }
30           else if(R==1&&Y==1&&B==1) //3个1
31           {
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个0
35           {
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个0
39           {
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个1
43           {
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个1
47           {
48               ans = 1;
49           }
50           else ans = 0; //2个0,1个1,3个0
51       }
52       printf("%I64d\n",ans);
53   }
54   return 0;
55 }

 

2013nanjingJ

标签:des   style   blog   http   color   io   os   ar   for   

原文地址:http://www.cnblogs.com/haohaooo/p/4018056.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!