zoukankan      html  css  js  c++  java
  • HDU-4811-Ball(思维)

    链接:

    https://vjudge.net/problem/HDU-4811

    题意:

    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?

    思路:

    构造左右两边,最多左边三个不同,右边三个不同,将剩下的乘进去即可.

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <vector>
    //#include <memory.h>
    #include <queue>
    #include <set>
    #include <map>
    #include <algorithm>
    #include <math.h>
    #include <stack>
    #include <string>
    #include <assert.h>
    #include <iomanip>
    #define MINF 0x3f3f3f3f
    using namespace std;
    typedef long long LL;
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int t;
        LL le, ri, r, y, b;
        while (cin >> r >> y >> b)
        {
            le = ri = 0;
            LL res = 0;
    
            if (r > 0)
                le++, r--;
            if (y > 0)
                res += le, le++, y--;
            if (b > 0)
                res += le, le++, b--;
    
            if (r > 0)
                ri++, r--, res += le;
            if (y > 0)
                res += le+ri, ri++, y--;
            if (b > 0)
                res += le+ri, ri++, b--;
    
            res += (r+y+b)*(le+ri);
            cout << res << endl;
        }
    
        return 0;
    }
    
  • 相关阅读:
    英语语法基础知识总结名词
    英语语法基础知识代词
    idea破解第二部
    Linux(centos)系统下安装fastdfs安装部署步骤
    死磕Synchronized底层实现概论偏向锁轻量级锁重量级锁
    深入理解Mysql事务隔离级别与锁机制
    事务的传播机制
    ICCV2021 | TokenstoToken ViT:在ImageNet上从零训练Vision Transformer
    计算机视觉CV技术指南文章汇总
    资源分享 | PyTea:不用运行代码,静态分析pytorch模型的错误
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11374429.html
Copyright © 2011-2022 走看看