题目链接:

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?
 
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
 
题意:
 
给出三种球的个数,然后再求题目要求的那个最大值;
 
思路:
 
分情况讨论啦,比如现在现在三种球的个数都大于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;
}

  

 

最新文章

  1. Electron的环境配置
  2. delphi中线程应用之Synchronize
  3. JavaScript判断图片是否加载完成的三种方式
  4. tp框架 中的时间 查询范围
  5. 关于MySQL的Admin Ping Command
  6. POJ C++程序设计 编程题#2 编程作业—文件操作与模板
  7. 函数lock_rec_get_first_on_page
  8. Struts2+hibernate3+Spring2的整合方法
  9. Java网络编程--echo服务器
  10. 系统变量写在.bash_profile和.bashrc的区别
  11. 职业定位(移动端、ios开发、Android开发)
  12. 根据优先关系矩阵使用逐次加一发构造优先函数(Java)
  13. 201521123039《Java程序设计》第十三周学习总结
  14. Cookie 判断页面是否为第一次打开 包括刷新
  15. golang 常量
  16. gitlab--ci文件
  17. Redis学习笔记--Redis数据过期策略详解==转
  18. 团队作业M1反思
  19. cpu占用过高排查
  20. 启动LINUX系统后,进入图形化界面的命令

热门文章

  1. jdk1.8 ThreadPoolExecutor实现机制分析
  2. ubuntu14.0安装arm-linux-gcc交叉编译环境
  3. android XMl 解析神奇xstream 六: 把集合list 转化为 XML文档
  4. 认识Runtime2
  5. 【读书笔记】iOS-防止通讯协议被轻易破解的方法
  6. BeanFactory not initialized or already closed - call &#39;refresh&#39; before accessing beans解决办法
  7. Struts2(十)OGNL标签二与Struts2标签
  8. PL/SQL基础1(笔记)
  9. Unity与Android的相互交互
  10. 谷歌浏览器 模拟微信浏览器user-agent