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/
  • 相关阅读:
    SpringCloud整合过程中jar依赖踩坑经验
    spring-boot-starter-parent的主要作用
    配置Setting.xml文件提高maven更新下载jar包速度
    剑指Offer-编程详解-二维数组中的查找
    Git 拉取Gitee仓库报错:“fatal: unable to access ''": Failed to connect to 127.0.0.1 port 1080: Connection refused”
    SpringBoot整合mybatis——配置mybatis驼峰命名规则自动转换
    SpringBoot 整合 Mybatis + Mysql——XML配置方式
    ES+open-falcon之nginx状态码监控报警自动化
    zabbix告警邮件美化
    基于Jenkins+Gitlab的自动化部署实战
  • 原文地址:https://www.cnblogs.com/lllxq/p/8839613.html
Copyright © 2011-2022 走看看