题目链接: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. 重新安装了环境报错{"error":"could not find driver"}

    前言:最近新工作开发oa系统,没有借助工具安装wamp环境,结果在测试项目时候出现了bug,找了很久,发现方向没有对 报错信息: {"error":"could not ...

  2. day20面向对象三大特性 , 类嵌套

    #!/usr/bin/env python# -*- coding:utf-8 -*- # 1.简述面向对象三大特性并用代码表示."""封装:class Account: ...

  3. Aras前端的一些知识

    top.aras包含了aras前端大部分的API /* * uiShowItem * 打开物体视窗 * parameters: * 1) itemTypeName - may be empty str ...

  4. 题解 P1801 【黑匣子_NOI导刊2010提高(06)】

    蒟蒻来发题解了.我仔细看了一下其他题解,各位巨佬用了堆,红黑树,splay,treap之类的强大算法,表示蒟蒻的我只会口胡这些算法,所以我决定用一种极其易理解的算法————fhq treap,作为tr ...

  5. java基于redis事务的秒杀实现

    package com.vian.user.service; import org.junit.Test; import org.springframework.util.CollectionUtil ...

  6. istio环境搭建for macbook

    首先需要搭建docker+k8s环境,如何搭建这里就不再赘述,可以自行搜索. 打开命令行,运行命令: curl -L https://git.io/getLatestIstio | ISTIO_VER ...

  7. python 中的__new__方法

    1.有关__new__方法的介绍 __new__方法调用在构造方法构造实例之前,即在__init__方法执行之前,我们可以这样理解,他的作用是决定是否适用这个__iint__方法来构造实例,但是需要注 ...

  8. axios formData提交数据 && axios设置charset无效???

    但是这样会出现一个问题,什么问题呢? 我设置了请求头编码utf-8,但是没生效 content-type里面没有出现utf-8???????查了很多资料,说这是axios固有的bug,我....... ...

  9. 普通用户授予select any table 权限

    基于应用的需要,让普通用户有访问sys表的权限,于是就想到了select any table 的权限,可是当授权以后发现还是不能访问sys的表,经过查一系列资料,发现select any table不 ...

  10. C语言尝试在不同源文件中调用程序段

    基于Visual Studio 2015 将下面两个cpp文件置于同一源文件目录下即可 源.cpp #include <stdio.h> int main() { extern int s ...