题意描述:
玩了这么多游戏,V决定还是去做几道ACM题练练手,于是翻到了一道201X年ACM/ICPC亚洲区域赛某站的现场赛签到试题,但是由于多年不刷题,已经忘了怎么做了
作为将来的ACM校队扛把子的你,请帮助他解决一下吧。
现场赛题目如下:
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?
hint:对于志在区域赛的acmer们,数学思维和英语读题能力是必不可少的 : )
hint again: 感谢husy(胡胜勇)对本次周赛试题的数据测试及标程提供
输入:
多实例
输入T,表示共有T组数据(T=100)
每组数据包含三个整数R,Y,B (0<= R,Y,B <=10000)
输出:
对于每组输入,输出最高得分
样例输入:
3 2 2 2 3 3 3 4 4 4
样例输出:
15 33 51
解题思路:这个题就是一个模拟的过程,因为题上说总和分最大也就是每一次放球都要保证得分最大。
1、当只有一种颜色球的时候,最后得分每一次最高为2;
2、当只有两种颜色的球和其中一种颜色球只有一个时候,最后每一次得到的最高分为3;
3、当只有两种颜色的球的时候 ,最后每一次得分最高为4;
4、当其中两种颜色的球只有一个的时候,最后每次最高得分为4;
5、当一种颜色球为1个另一个颜色球为2的时候,最后每次最高得分为5;
6、当一种颜色球为1,其余都大于2的时候,最后每次得分最高为5;
7、当三种颜色球都大于2的时候,最后每次得分最高为6;
程序代码:
#include<stdio.h> int main() { int i,n,m,j,k,T; long long a,b,c,sum; scanf("%d",&T); while(T--) { sum=0; scanf("%lld%lld%lld",&a,&b,&c); n=a+b+c; if(n==0||n==1) sum=0; if(n>=2) sum+=1; if(n>=3) sum+=2; if((a==0&&b==0)||(a==0&&c==0)||(c==0&&b==0)) { if(n>=4) sum+=2*(n-3); } else if((a==0&&b==1)||(a==0&&c==1)||(c==0&&b==1)||((c==0&&a==1)||(b==0&&a==1)||(b==0&&c==1))) { if(n>=3) sum+=3*(n-3); } else if((a==0&&b>1)||(a==0&&c>1)||(c==0&&b>1)||((c==0&&a>1)||(b==0&&a>1)||(b==0&&c>1))) { if(n>=4) sum+=3; if(n>=5) sum+=4*(n-4); } else if((a==1&&b==1)||(a==1&&c==1)||(c==1&&b==1)||((c==1&&a==1)||(b==1&&a==1)||(b==1&&c==1))) { if(n>=4) sum+=3; if(n>=5) sum+=4*(n-4); } else if((a==1&&b==2)||(a==1&&c==2)||(c==1&&b==2)||((c==1&&a==2)||(b==1&&a==2)||(b==1&&c==2))) { if(n>=4) sum+=3; if(n>=5) sum+=4; if(n>=6) sum+=5*(n-5); } else if((a==1&&b>2)||(a==1&&c>2)||(c==1&&b>2)||((c==1&&a>2)||(b==1&&a>2)||(b==1&&c>2))) { if(n>=4) sum+=3; if(n>=5) sum+=4; if(n>=6) sum+=5*(n-5); } else if((a>=2&&b>=2&&c>=2)||(a>=2&&c>=2&&b>=2)||(a>=2&&c>=2&&b>=2)||((b>=2&&c>=2&&a>=2)||(c>=2&&b>=2&&a>=2)||(a>=2&&b>=2&&c>=2))) { if(n>=4) sum+=3; if(n>=5) sum+=4; if(n>=6) sum+=5; if(n>=7) sum+=6*(n-6); } printf("%lld\n",sum); } return 0; }