题目链接:

题目

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. 运用DataTable进行行转列操作

    public DataTable GetReverseTable(DataTable p_Table) { DataTable _Table = new DataTable(); ; i != p_T ...

  2. list转换成DataTable

    list转换成DataTable类如下: public static DataTable ToDataTable<T>(this IList<T> datas) { DataT ...

  3. Java之组合数组1

    我们先说"数组",数组是有序数据的集合,数组中的每个元素具有相同的数组名和下标来唯一地确定数组中的元素. 一.一维数组的定义 type arrayName[]; 其中类型(type ...

  4. IOS显示九宫格列表

    //总列数 ; CGFloat appW = ; CGFloat appH = ; //间隙 CGFloat maginX = (self.view.frame.size.width - totalC ...

  5. Row_Number实现分页(适用SQL)

    1:首先是 select ROW_NUMBER() over(order by id asc) as 'rowNumber', * from table1 生成带序号的集合 2:再查询该集合的 第 1 ...

  6. 转: 理解Python的With语句

    Python’s with statement provides a very convenient way of dealing with the situation where you have ...

  7. HTML特殊字符编码大全

    HTML特殊字符编码大全:往网页中输入特殊字符,需在html代码中加入以&开头的字母组合或以&#开头的数字.下面就是以字母或数字表示的 特殊符号大全 ´ © © > > µ ...

  8. 7款震撼人心的HTML5文字特效

    1.CSS3五彩文字特效 文字带阴影效果 这是一款非常具有卡通形象的CSS3五彩文字特效,虽然没有迷人的动画效果,但是五彩缤纷的文字展现在屏幕上也是非常酷的,再加上每一个文字都有不同角度的阴影效果,加 ...

  9. c++11之右值引用

    本文大部分来自这里,并不是完全着行翻译,如有不明白的地方请参考原文. 在c++中,创建临时对象的开销对程序的影响一直很大,比如以下这个例子: String getName(){ return “Kia ...

  10. matlab 直方图均衡化

    原理: 直方图均衡化首先是一种灰度级变换的方法: 原来的灰度范围[r0,rk]变换到[s0,sk]变换函数为:s=T(r); 为便于实现,可以用查找表(look-up table)的方式存储,即:原始 ...