问题 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.
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.
• 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;
}