HDU

来源:互联网 发布:双色球蓝球算法 编辑:程序博客网 时间:2024/05/29 08:26
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 23 3 34 4 4
Sample Output
1533

51

比较简单,不详细说了

ac代码:

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;int main(){    int x,y,z;    long long sum;    int k;    while(scanf("%d%d%d",&x,&y,&z)!=-1)    {        k=0;      sum=x+y+z;      int g=0;      if(x>0)      g++;      if(y>0)      g++;      if(z>0)      g++;      if(x>=2)      {          k+=2;          sum-=2;      }      else      {          k+=x;          sum-=x;      }      if(y>=2)      {          k+=2;          sum-=2;      }      else      {          k+=y;          sum-=y;      }      if(z>=2)      {          k+=2;          sum-=2;      }      else      {          k+=z;          sum-=z;      }      if(k==0||k==1)      cout<<0<<endl;      if(k==2)      {          if(g==1)          cout<<1+sum*2<<endl;          if(g==2)          cout<<1<<endl;      }      if(k==3)      {          if(g==2)          cout<<3+3*sum<<endl;          if(g==3)          cout<<3<<endl;      }      if(k==4)      {          cout<<6+sum*4<<endl;      }      if(k==5)      {          cout<<10+sum*5<<endl;      }      if(k==6)      cout<<15+sum*6<<endl;    }    return 0;}

0 0
原创粉丝点击