zoukankan      html  css  js  c++  java
  • Ball HDU

    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?

    InputThere 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.OutputFor 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


    这题题目不难,看懂题目难! 特别是对于英语基础不好的我来说,简直是炼狱,靠猜题意为生。
    题意:
    有红黄蓝三种颜色的球,要求依次把球排成一列。
    只有一个球的分数时为0,依次放球,放在两端的时候所加的分数为之前球颜色的种类,
    把球放在中间时所加的分数为这个放的球的两边的球的颜色的种类。
        求出放完球最后的分数为多少?
    这题做的方法特别多,我第一次做的时候想不出简单的方法,然后就是不断枚举,找到其中的规律。
    下面放出我第一次做的代码,相信读者很容易看出其中的规律
     
     1 #include "cstdio"
     2 #include "cstring"
     3 #include <math.h>
     4 #include "cstdlib"
     5 #include "iostream"
     6 #include<algorithm>
     7 using namespace std;
     8 
     9 int main() {
    10     long long a[5];
    11     long long sum;
    12     while(scanf("%lld%lld%lld",&a[0],&a[1],&a[2])!=EOF){
    13         sort(a,a+3);
    14         sum=0;
    15         if (a[0]>=2 && a[1]>=2 && a[2]>=2) sum=15+((a[0]+a[1]+a[2])-6)*6;
    16         else if (a[0]==0 && a[1]==0 && a[2]==0) sum=0;
    17         else if (a[0]==0 && a[1]==0 && a[2]==1) sum=0;
    18         else if (a[0]==0 && a[1]==0 && a[2]>=2)  sum=1+(a[2]-2)*2;
    19         else if (a[0]==0 && a[1]==1 && a[2]==1) sum=1;
    20         else if (a[0]==0 && a[1]==1 && a[2]>=2)  sum=3+(a[2]-2)*3;
    21         else if (a[0]==1 && a[1]==1 && a[2]==1) sum=3;
    22         else if (a[0]==1 && a[1]==1 && a[2]>=2)  sum=6+(a[2]-2)*4;
    23         else if (a[0]==0 && a[1]>=2  && a[2]>=2)  sum=6+(a[2]+a[1]-4)*4;
    24         else if (a[0]==1 && a[1]>=2 && a[2]>=2)   sum=10+(a[2]+a[1]-4)*5;
    25         printf("%lld
    ",sum);
    26         memset(a,0,sizeof(a));
    27     }
    28     return 0;
    29 }

    以上的方法是纯粹的暴力 个人感觉是非常蠢的。
    下面的代码简短,就是以上代码的概括


     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 #include<queue>
     7 using namespace std;
     8 long long get(long long  x)
     9 {
    10     if (x>=2) return 2;
    11     else return x;
    12 }
    13 int main() {
    14     long long a,b,c;
    15     while(scanf("%lld%lld%lld",&a,&b,&c)!=EOF){
    16         long long x=get(a)+get(b)+get(c);
    17         long long y=a+b+c-x;
    18         long long z=y*x+(x-1)*x/2;
    19         printf("%lld
    ",z);
    20     }
    21     return 0;
    22 }
  • 相关阅读:
    【bzoj1707/Usaco2007 Nov】tanning分配防晒霜——贪心+优先队列
    【bzoj1754/Usaco2005 qua】Bull Math——高精度乘法
    【bzoj1709/Usaco2007 Oct】Super Paintball超级弹珠——递推
    【bzoj2060/Usaco2010 Nov】Visiting Cows 拜访奶牛——树形dp
    【bzoj1710/Usaco2007 Open】Cheappal 廉价回文——区间dp
    【bzoj1828/Usaco2010 Mar】balloc 农场分配——贪心+差分+优先队列
    【bzoj4552/Tjoi2016&Heoi2016】排序——二分+线段树/平衡树+线段树分裂与合并
    【bzoj2083/Poi2010】Intelligence test——二分+贪心
    【bzoj1596/Usaco2008 Jan】电话网络——dfs
    【bzoj1782/Usaco2010 Feb】slowdown 慢慢游——dfs序+树状数组
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/8510779.html
Copyright © 2011-2022 走看看