题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4811

题目描述:

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

题意:

有三种颜色,给你每种颜色的球的数量,有以下两种得分方式,问你如何放置这些球,让总得分最大。

方式一:放第一个球的得分为0

方式二:放在最后面的得分为之前的所有球的颜色种数

方式三:放在中间的得分为左边球的颜色种数+右边球的颜色种数

思路:

找规律,推导出公式,因为只有三种颜色,如果每种颜色都有2的及以上,那么可以先在两边各摆三种颜色的球,这样每次把其他球放入中间时都能得到6分,即ans=(R-2+Y-2+B-2)*6+15(15为在两边各摆三种颜色的球的过程所获得的总得分)。

其实如果一个球的数量超过了2,那么剩下的就是一个乘法了。 这个理解很简单,因为超过了2的话,说明最优的方案一定是左右各一个,不然如果都在一边的话就只得1分了。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long ll;
using namespace std; ll a[][][];//a[i][j][k]表示红色球为i个,黄色球为j个,蓝色球为k个的排列总数
ll f[],n,k,tep; int main()
{
a[][][]=,a[][][]=,a[][][]=,a[][][]=,a[][][]=,a[][][]=;
a[][][]=,a[][][]=,a[][][]=,a[][][]=;
while (cin>>f[]>>f[]>>f[])
{
n=k=;
for (int i=; i<; i++)
{
if (f[i]>) k=;
else k=f[i];
n+=f[i]-k,f[i]=k;
}
sort(f+,f+);
tep=f[]+f[]+f[];
cout<<a[f[]][f[]][f[]]+n*tep<<endl;
} return ;
}
 

hdu4811-Ball(2013ACM/ICPC亚洲区南京站现场赛)的更多相关文章

  1. 2013ACM/ICPC亚洲区南京站现场赛---Poor Warehouse Keeper(贪心)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4803 Problem Description Jenny is a warehouse keeper. ...

  2. 2013ACM/ICPC亚洲区南京站现场赛-HDU4809(树形DP)

    为了这个题解第一次写东西..(我只是来膜拜爱看touhou的出题人的).. 首先以为对称性质..我们求出露琪诺的魔法值的期望就可以了..之后乘以3就是答案..(话说她那么笨..能算出来么..⑨⑨⑨⑨⑨ ...

  3. 2013ACM/ICPC亚洲区南京站现场赛——题目重现

    GPA http://acm.hdu.edu.cn/showproblem.php?pid=4802 签到题,输入两个表,注意细心点就行了. #include<cstdio> #inclu ...

  4. 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)

    摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...

  5. 2016ACM/ICPC亚洲区大连站现场赛题解报告(转)

    http://blog.csdn.net/queuelovestack/article/details/53055418 下午重现了一下大连赛区的比赛,感觉有点神奇,重现时居然改了现场赛的数据范围,原 ...

  6. 2013ACM-ICPC亚洲区南京站现场赛G题

    题目大意:一个n维的系统中随机选一个向量(X1,X2,X3,...,Xn),其中0<=Xi<=R,且X1^2+X2^2+X3^2+……+Xn^2 <= R^2. 现在给定n,R.求X ...

  7. 2014ACM/ICPC亚洲区西安站现场赛 F color(二项式反演)

    题意:小球排成一排,从m种颜色中选取k种颜色给n个球上色,要求相邻的球的颜色不同,求可行的方案数,答案模1e9+7.T组数据,1<= n, m <= 1e9, 1 <= k < ...

  8. HDU 6227.Rabbits-规律 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))

    Rabbits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  9. HDU 6225.Little Boxes-大数加法 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))

    整理代码... Little Boxes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/O ...

随机推荐

  1. js原生触发事件

    在JQ时代我们使用如下方式,可以手动触发事件 $("button").click(function(){ $("input").trigger("se ...

  2. Maven(二)名词、命令、仓库、依赖、私服

    这篇文章将Maven其他内容做一个介绍. 一.名词 ①:localRepository 本地仓库路径,位于maven/conf/settings.xml中. ②:project  项目. ③:pom  ...

  3. Eclipse——如何设置代码字体大小

    eclipse默认字体太小,1920*1080下分辨不清楚,接下来介绍一下如何更改默认字体大小: 1.window-Preferences 2.General-Appearance-Colors an ...

  4. [算法竞赛入门经典]Message Decoding,ACM/ICPC World Finals 1991,UVa213

    Description Some message encoding schemes require that an encoded message be sent in two parts. The ...

  5. move_base Warning: Invalid argument "/map" passed to canTransform argument target_frame的解决方法

    把global_costmap_params.yaml和local_costmap_params.yaml文件里的头几行去掉“/”,然后重新编译就可以了. 效果如下:

  6. Kafka安装配置

    Kafka是由Apache软件基金会开发的一个高吞吐量的分布式发布订阅消息系统,由Scala和Java编写.官网地址:http://kafka.apache.org 0.基本概念 Broker:Kaf ...

  7. centos环境下安装redis

    1.安装gcc和gcc-c++ 使用which gcc 和which g++检查是否已经安装,若已有安装,跳过下面安装步骤 安装gcc yum -y install gcc 安装gcc-c++ yum ...

  8. 关于lnmp下 phalcon和tp框架下的nginx文件配置

    vim /etc/nginx/sites-available/default   进入修改目录 1.正常项目配置 server { listen 80 default_server; listen [ ...

  9. Theano.tensor.round函数学习,同时解决输出Elemwise{xxx,no_inplace}.0的问题

    1. 出现Elemwise{xxx,no_inplace}.0   这是因为没有定义theano.function所致,参考下面错误示范: y = np.random.normal(size=(2,2 ...

  10. LeetCode第二十二题-创建n对括号

    Generate Parentheses 问题简介: 给定n对括号,编写一个函数来生成格式正确的括号的所有组合. 举例: 给定n = 2,解集是: [ “()()”, “(())” ] 给定n = 3 ...