首页 > ACM题库 > HDU-杭电 > HDU 4811-Ball-模拟-[解题报告]HOJ
2015
09-18

HDU 4811-Ball-模拟-[解题报告]HOJ

Ball

问题描述 :

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.

输出:

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.

样例输入:

2 2 2
3 3 3
4 4 4

样例输出:

15
33
51

题意:有三种颜色的球,并排放在桌子上,如果放当前球的时候左边有x种球右边有y种球的话可以得到x+y点点数,问最多能得到多少点数。

每次放球优先往中间放,如果两边都能凑够三色那么后来的计算肯定就是固定的,如果没凑够的话少一种颜色就-1…大概是这样解释的吧- -,本题目有个弱化版的,可以先去做做弱化版的,理解更快点,附上链接:Happy Thanksgiving Day – The Magical Candy

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
using namespace std;
int main()
{
    int f[5]={0,0,1,3};
    int x,y,z;
    int qian,hou;
    while(cin>>x>>y>>z)
    {
        long long ans=0;
        qian=hou=0;
        if(x>0){qian++;x--;}//往前面加不用颜色的先
        if(y>0){qian++,y--;}
        if(z>0){qian++,z--;}
        if(x>0){hou++,x--;}//往后面加不同的颜色
        if(y>0){hou++,y--;}
        if(z>0){hou++,z--;}
        ans+=f[qian];
        ans+=qian*hou+f[hou];//计算一下把两边都放好获得的点数
        ans+=(long long)(qian+hou)*(x+y+z);//因为两边的状态已经放好,后来的计算就是固定的
        cout<<ans<<endl;
    }
    return 0;
}

参考:http://blog.csdn.net/azx736420641/article/details/41679125