2013南京站J题||hdu 4811 思维

本文介绍了一种关于球的不同颜色排列及其计分规则的算法问题。通过合理的球色分布策略,计算放置球过程中可以获得的最大总分数。文章给出了具体的实现代码,并通过样例输入输出展示了解决方案的有效性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 10 9.
 

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
解题思路:我的方法是先把x,y,z三个数的0~2的组合列出来,然后多于2的部分每增加一可以取得分数为一定的。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll f[3],k;
ll sum[3][3][3];
int main()
{
    sum[0][0][0]=0;
    sum[0][0][1]=0;
    sum[0][0][2]=1;
    sum[0][1][1]=1;
    sum[0][1][2]=3;
    sum[0][2][2]=6;
    sum[1][1][1]=3;
    sum[1][1][2]=6;
    sum[1][2][2]=10;
    sum[2][2][2]=15;
    while(~scanf("%I64d%I64d%I64d",&f[0],&f[1],&f[2]))
    {
        ll n=0,m=0;
        sort(f,f+3);
        for(int i=0;i<3;i++)
        {
            if(f[i]>2)
                k=2;
            else
                k=f[i];
            n+=f[i]-k,f[i]=k;
            m+=f[i];
        }
        printf("%I64d\n",sum[f[0]][f[1]][f[2]]+n*m);
    }
    return 0;
}


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 10 9.
 

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值