题目链接:

题目

Ball

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 32768/32768 K (Java/Others)

问题描述

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?

输入

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.

输出

For each test case, print the answer in one line.

样例

input

2 2 2

3 3 3

4 4 4

output

15

33

51

题意

给你三种颜色的气球各若干个。现在把所有的气球放成一排,放第一个没有贡献值,之后每放一个气球,贡献值等于放在这个气球左边的不同颜色种类数加上放在这个气球右边的不同颜色种类数。最后要求一种摆放方案使得所有贡献值的总和的最大值。

题解

各种分类讨论的挫代码orz:

#include<cstdio>
#include<algorithm>
using namespace std; typedef long long LL; int main() {
int tc,kase=0;
LL a[22];
while(scanf("%lld%lld%lld",&a[0],&a[1],&a[2])==3) {
sort(a,a+3);
if(a[0]>=2&&a[1]>=2&&a[2]>=2) {
LL ans=15+6*(a[0]+a[1]+a[2]-6);
printf("%lld\n",ans);
} else if(a[0]>=1&&a[1]>=1&&a[2]>=1){
a[0]--; a[1]--; a[2]--;
LL ans=3;
if(a[1]>=1&&a[2]>=1){
ans+=7+5*(a[1]+a[2]-2);
}else if(a[2]>0){
ans+=3+(a[2]-1)*4;
}
printf("%lld\n",ans);
}else{
LL ans=0;
if(a[1]>=2&&a[2]>=2){
ans=6+(a[1]+a[2]-4)*4;
}else if(a[1]>=1&&a[2]>=1){
ans=1;
a[1]--; a[2]--;
if(a[2]>0){
ans+=2+(a[2]-1)*3;
}
}else{
a[2]--;
if(a[2]>0){
ans=1+2*(a[2]-1);
}else{
ans=0;
}
}
printf("%lld\n",ans);
}
}
return 0;
}

优化之后的:(这很优化)

首先,每种颜色取出两个(不足两个的有几个选几个),易知先取出来的这几个数可以取到最好的情况(一个等差数列),之后我们采取贪心的策略在中间放,同样也是最优的。 假设我们能先取出x个(x<=6),那我们形成的最优序列就是:1 2 3 4 5 5 5 5 ... 5; 答案就是:x(x-1)/2+x(sum-x);

#include<stdio.h>
#include<algorithm>
typedef long long LL;
int main(){
int a[3];
while(scanf("%d%d%d",&a[0],&a[1],&a[2])==3){
LL cnt=0;
for(int i=0;i<3;i++) cnt+=std::min(2,a[i]);
cnt=cnt*(cnt-1)/2+cnt*((LL)a[0]+a[1]+a[2]-cnt);
printf("%lld\n",cnt);
}
return 0;
}

HDU 4811 Ball 贪心的更多相关文章

  1. hdu 5821 Ball 贪心

    Ball 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes nu ...

  2. HDU 5821 Ball (贪心排序) -2016杭电多校联合第8场

    题目:传送门. 题意:T组数据,每组给定一个n一个m,在给定两个长度为n的数组a和b,再给定m次操作,每次给定l和r,每次可以把[l,r]的数进行任意调换位置,问能否在转换后使得a数组变成b数组. 题 ...

  3. HDU 4811 Ball -2013 ICPC南京区域现场赛

    题目链接 题意:三种颜色的球,现给定三种球的数目,每次取其中一个放到桌子上,排成一条线,每次放的位置任意,问得到的最大得分. 把一个球放在末尾得到的分数是它以前球的颜色种数 把一个球放在中间得到的分数 ...

  4. [思考] hdu 4811 Ball

    意甲冠军: 有三种颜色的小珠,每种颜色的量R,Y,B 转球进入桌面成序,有多少种不同的颜色分别砍下的球在球门前+有多少身后球不同的颜色 问:最大的总比分值 思考: 球和后面的球先放好.剩下的就放中间了 ...

  5. HDU - 4811 - Ball (思维)

    题意: 给出一定数量的三种颜色的球,计算如何摆放得到值最大(有一定顺序) 有三种摆放方法 1.如果放的是第一个(桌子上原来没有),数值不变 2.如果在末尾追加一个,那么增加前面不同颜色的个数的值 3. ...

  6. Hdu 4864(Task 贪心)(Java实现)

    Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...

  7. D - 淡黄的长裙 HDU - 4221(贪心)

    D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...

  8. HDU 5821 Ball (贪心)

    Ball 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes nu ...

  9. HDU 4362 Dragon Ball 贪心DP

    Dragon Ball Problem Description   Sean has got a Treasure map which shows when and where the dragon ...

随机推荐

  1. Part 36 to 39 Talking about Delegates in c#

    Part 36 Delegates in c# Part 37 Delegates usage in c# class Progim { public static void Main() { Lis ...

  2. Flask Restful Small Demo

    参考: http://www.pythondoc.com/flask-restful/first.html 什么是Rest Client-Server:服务器端与客户端分离. Stateless(无状 ...

  3. DOS 批处理 修改xml文件

    之前对批处理和dos只停留在cd ping ipconfig水平,我以为改个文件应该很简单吧,把文件读出来做个替换再写回去不就欧了,百度个例子改改,那还不是分分钟的事,哪知道事实比想的要复杂的多. 我 ...

  4. 找不到命名空间命名空间:System.Windows.Forms

    System.Windows.Forms在system.windows.forms.dll中.需要添加引用.在解决方案资源管理器中的引用上单击右键,选择添加引用.找到System.windows.fo ...

  5. 用LINQ在集合中查询特定对象

    这里是原文出处: 简单的概括LINQ LINQ是Language-Integrated Query的缩写,是C# 3.0和VB 9.0中新加入的语言特性,可以在编程时使用内置的查询语言进行基于集合的操 ...

  6. 解决Toad for Oracle显示乱码问题

    1.查看一下数据库字符集: 使用下面语句:Select userenv('language') from dual;或者:Select name, value$ from props$;查看. 查看完 ...

  7. 【转】理解依赖注入(IOC)和学习Unity

    IOC:英文全称:Inversion of Control,中文名称:控制反转,它还有个名字叫依赖注入(Dependency Injection).作用:将各层的对象以松耦合的方式组织在一起,解耦,各 ...

  8. 实现简单的cp命令

    在Linux下实现简单的cp命令.这是<APUE>第四章的其中一道练习题. 其实思路很简单,弄清规则就行了.规则1:源文件必须得存在,否则出错:规则2:目的文件若不存在则创建,若存在,则提 ...

  9. linux命令行解析函数介绍

    函数原型:         int getopt(int argc,char * const argv[ ],const char * optstring);         给定了命令参数的数量 ( ...

  10. 关于Silverlight调用天气预报接口问题

    问题:因Silverlight客户端不能直接调用webservice接口(外网天气接口),调用会出现跨域访问的问题,即使添加了跨域文件也不好使.解决方法如下 解决方法一:1.在服务端建立一个wcf服务 ...