hdu-4811 Ball
生活随笔
收集整理的這篇文章主要介紹了
hdu-4811 Ball
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接:
Ball
Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2149????Accepted Submission(s): 897
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 題意: 給出三種球的個數,然后再求題目要求的那個最大值; 思路: 分情況討論啦,比如現在現在三種球的個數都大于2,那么在放球的話就可以最大得到6的分數了,然后其他的情況也是這樣啦; AC代碼: #include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn=1e5+10; int n,m,k; int main() {while(scanf("%d%d%d",&n,&m,&k)!=EOF){if(n>=2&&m>=2&&k>=2){LL ans=n-2+m-2+k-2;printf("%lld\n",ans*6+15);}else {int a[4];a[0]=n,a[1]=m,a[2]=k;sort(a,a+3);int num=0;for(int i=0;i<3;i++)if(a[i]==0)num++;if(num==3)printf("0\n");else if(num==2){if(a[2]==1)printf("0\n");else printf("%d\n",a[2]*2-3);}else if(num==1){if(a[2]==1)printf("1\n");else {if(a[1]==1){if(a[2]==1)printf("1\n");else {LL ans=a[2]-2;printf("%lld\n",3*ans+3);}}else {LL ans=a[1]-2+a[2]-2;printf("%lld\n",ans*4+6);}}}else {if(a[2]==1)printf("3\n");else {if(a[1]==1){LL ans=a[2]-2;printf("%lld\n",6+ans*4);}else {LL ans=a[1]-2+a[2]-2;printf("%lld\n",5*ans+10);}}}}}return 0; }
轉載于:https://www.cnblogs.com/zhangchengc919/p/5926647.html
總結
以上是生活随笔為你收集整理的hdu-4811 Ball的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 洛谷U4807抽水机[最小生成树]
- 下一篇: 了解JDBC