High Score--nwerc2017(思维)

2人阅读 评论(0) 收藏 举报
分类:

问题 H: High Score

时间限制: 2 Sec  内存限制: 128 MB
提交: 360  解决: 80
[提交][状态][讨论版][命题人:admin]

题目描述

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

题意:给你四个数a,b,c,d,d可任意分配给a,b,c,现在定义一个函数f=a*a+b*b+c*c+min(a,b,c),求该函数的最大值是多少。

题解:当d足够大时,直接把d分给一个元素,一定是最优的,当d比较小时,则可直接枚举所有情况找出最大值。

#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#define INF 0x3f3f3f3f
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
 
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
 
inline ll f(ll a,ll b,ll c){return a*a+b*b+c*c+min(a,min(b,c))*7;}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        ll a,b,c,d,ans,k;
        int maxn=100;
        cin>>a>>b>>c>>d;
        ans=0;
        for(int i=0;i<=d && i<=maxn;i++)
            for(int j=0;i+j<=d && j<=maxn;j++)
            {
                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+k,b+i,c+j));
            }
 
        ans=max(ans,f(a+d,b,c));
        ans=max(ans,f(a,b+d,c));
        ans=max(ans,f(a,b,c+d));
 
        cout<<ans<<endl;
    }
    return 0;
}
查看评论

macOS High Sierra 的锁屏功能

macOS High Sierra 的锁屏功能  2017-09-26 转载至: https://caixw.io/posts/2017/macos-high-sierra-lock-screen....
  • YLGWHYH
  • YLGWHYH
  • 2017-11-16 21:31:53
  • 1005

High Output Management

  • 2017年09月29日 14:09
  • 2.04MB
  • 下载

解决开机提示High Severity Error问题

安装完MySQL开机显示High Severity Error问题。
  • y694721975
  • y694721975
  • 2016-11-01 17:02:11
  • 2564

macOS Sierra 查看隐含文件

不需要额外操作,仅需按下 cmd+shift+. 组合键即可
  • ch21st
  • ch21st
  • 2016-10-09 16:56:18
  • 870

学习java的一些思维!

将业务逻辑放在JavaBean中   直接包含在jsp中的java代码并不象包含在JavaBean中的java代码那样容易被其他jsp页面理解,通用行为和业务逻辑放在JavaBean中不仅可以被其它...
  • u012402926
  • u012402926
  • 2016-07-27 17:47:28
  • 618

什么是工程思维和产品思维

在外行人眼里,工程师是一个死板、墨守成规、不会思变的工种。其实不然。 一、在工程上经常会遇到那些与设计无关的、但是或多或少能影响到工程效率的东西,要想提高效率,就要灵活运用你的工程思维。 下面举几...
  • k331922164
  • k331922164
  • 2015-06-14 15:34:21
  • 1703

金字塔思维学习总结

金字塔思维的总结回顾
  • yangcheng33
  • yangcheng33
  • 2016-08-29 00:54:06
  • 5908

【公开课】计算思维漫谈笔记

南华大学的公开课计算思维漫谈,从本质概念上阐述了计算和计算思维。记录下对自己有些启发的要点。 1、计算的发展过程 计算手段器械化计算过程形式化 图灵概念:用机器来模拟人们用纸、笔进行数学...
  • foreverphoenix
  • foreverphoenix
  • 2014-04-10 14:35:01
  • 1591

系统化思维导论.pdf

  • 2009年01月04日 20:23
  • 12.3MB
  • 下载

High Definition Audio Driver 没有驱动起来解决经验

  • 2009年05月06日 23:51
  • 6.7MB
  • 下载
    个人资料
    持之以恒
    等级:
    访问量: 759
    积分: 558
    排名: 9万+
    文章存档
    最新评论