zoukankan      html  css  js  c++  java
  • [枚举]High Score

    题目描述

    Mårten and Simon enjoy playing the popular board game Seven Wonders, and have just finished a match. It is now time to tally the scores.

    One of the ways to score in Seven Wonders is through the use of Science. During the game, the players may collect a number of Science tokens of three different types: Cog, Tablet, and Compass. If a player has a Cogs, b Tablets and c Compasses, that player gets a2 + b2 + c2 + 7 · min(a, b, c) points. 

    However, the scoring is complicated by the concept of Wildcard Science tokens. For each Wildcard Science token a player has, she may count that as one of the three ordinary types of Science tokens. For instance, the first player in Sample Input 1 has 2 Cogs, 1 Tablet, 2 Compasses, and 1 Wildcard Science, so could thus choose to have the distributions (3, 1, 2), (2, 2, 2) or (2, 1, 3) of Cogs, Tablets and Compasses, respectively. The possible scores for this player are then 32 + 12 + 22 + 7 · 1 = 21, 22 + 22 + 22 + 7 · 2 = 26 and 22 + 12 + 32 + 7 · 1 = 21 depending on how the Wildcard Science is assigned. Thus, the maximum score for this player is 26.
    Given the number of tokens each player in the game has, compute the maximum possible score that each of them can achieve if they assign their Wildcard Science tokens optimally.

    输入

    The input consists of:
    • One line with an integer n (3 ≤ n ≤ 7), the number of players in the game.
    • n lines, each with four integers a, b, c, d (0 ≤ a, b, c, d ≤ 109 ), giving the number of Cog,Tablet, Compass, and Wildcard Science tokens of a player.

    输出

    For each player, in the same order they are given in the input, output the maximum score the player may get.

    样例输入

    3
    2 1 2 1
    3 2 1 0
    1 3 0 1
    

    样例输出

    26
    21
    18

    题意:将d分成三个数,将这三个数加到a,b,c上得到a',b',c',求a'*a'+b'*b'+c'*c'+7*min(a',b',c')的最大值
    思路:暴力枚举d分出来的三个数i,j,k,显然超时.发现,当d较大时,最优策略是将d全部加在max(a,b,c)上(平方增长较快),而d较小时则不一定成立
    综上,当d大于1e3时,d全部加在max(a,b,c)上;当d小于等于1e3时,暴力枚举i,j,k寻找最大值
    AC代码:
    #include <iostream>
    #include<cstdio>
    #include<algorithm>
    #define ll long long
    using namespace std;
    
    ll f(ll a,ll b,ll c){
      return a*a+b*b+c*c+7*min(a,min(b,c));
    }
    
    int main()
    {
        int n;
        scanf("%d",&n);
        while(n--){
            ll a,b,c,d;
            scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
            ll ans=0;
            ans=max(ans,f(a+d,b,c));
            ans=max(ans,f(a,b+d,c));
            ans=max(ans,f(a,b,c+d));
            if(d<=1000){
            for(ll i=0;i<=d;i++){
                for(ll j=0;j<=d-i;j++){
                    ll k=d-i-j;
                    ans=max(ans,f(a+i,b+j,c+k));
                    ans=max(ans,f(a+i,b+k,c+j));
                    ans=max(ans,f(a+j,b+i,c+k));
                    ans=max(ans,f(a+j,b+k,c+i));
                    ans=max(ans,f(a+k,b+i,c+j));
                    ans=max(ans,f(a+k,b+j,c+i));
                }
            }
            }
            printf("%lld
    ",ans);
        }
        return 0;
    }

    论暴力的重要性。

    转载请注明出处:https://www.cnblogs.com/lllxq/
  • 相关阅读:
    SQL 触发器[1]
    SQL 存储过程[1]-常用参数及示例
    前端软件开发体系
    人工智能AI Boosting HMC Memory Chip
    先进一站式IP及定制
    BTC芯片介绍
    ONNX MLIR方法
    MLIR中间表示和编译器框架
    Non-Maximum Suppression,NMS非极大值抑制
    华为计算平台MDC810发布量产
  • 原文地址:https://www.cnblogs.com/lllxq/p/8839613.html
Copyright © 2011-2022 走看看