hdu-6435 CSGO

Problem J. CSGO

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 635    Accepted Submission(s): 334


 

Problem Description

You are playing CSGO.
There are n Main Weapons and m Secondary Weapons in CSGO. You can only choose one Main Weapon and one Secondary Weapon. For each weapon, it has a composite score S.
The higher the composite score of the weapon is, the better for you.
Also each weapon has K performance evaluations x[1], x[2], …, x[K].(range, firing rate, recoil, weight…)
So you shold consider the cooperation of your weapons, you want two weapons that have big difference in each performance, for example, AWP + CZ75 is a good choose, and so do AK47 + Desert Eagle.
All in all, you will evaluate your weapons by this formula.(MW for Main Weapon and SW for Secondary Weapon)


Now you have to choose your best Main Weapon & Secondary Weapon and output the maximum evaluation.  

Input

Multiple query.
On the first line, there is a positive integer T, which describe the number of data. Next there are T groups of data.
for each group, the first line have three positive integers n, m, K.
then, the next n line will describe n Main Weapons, K+1 integers each line S, x[1], x[2], …, x[K]
then, the next m line will describe m Secondary Weapons, K+1 integers each line S, x[1], x[2], …, x[K]
There is a blank line before each groups of data.
T<=100, n<=100000, m<=100000, K<=5, 0<=S<=1e9, |x[i]|<=1e9, sum of (n+m)<=300000

 

Output

Your output should include T lines, for each line, output the maximum evaluation for the corresponding datum.

 

Sample Input

 

2

2 2 1

0 233

0 666

0 123

0 456

2 2 1

100 0

1000 100

1000 100

100 0

 

Sample Output

 

543

2000

//题目大意:有n把主武器,m把副武器,每把武器有k个属性值,挑选主副武器各一把,根据公式计算,使得值最大

//思路:由于| Xmw[i]-Xsw[i] |=| Xsw[i]-Xmw[i] | ,即计算时,每把武器的个x[i]有两种状态,所以共有pow(2,k)种可能,由于k很小,所以可以考虑将pow(2,k)中情况枚举出来,然后找出 主武器与其相应的副武器的和 的最大值;

举个栗子:

n=m=k=2;

10 1 2

11 4 5

9 3 4

8 1 3

加减情况:00  01  10  11 (0表示减,1表示加)

mw             7   12  10   20

sw              4   10   8    16

所以最大值为mw[3]+sw[0]=20+4=24;

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
int main()
{
    int t;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            int n,m,k;
            scanf("%d%d%d",&n,&m,&k);
            ll mw[100],sw[100];
            for(int i=0;i<100;i++)mw[i]=sw[i]=-0x3f3f3f3f;
            ll x[10];
            int len=1<<k;
            for(int i=0;i<n;i++)
            {
                ll s;
                scanf("%lld",&s);
                for(int j=0;j<k;j++)scanf("%lld",&x[j]);
                for(int p=0;p<len;p++)
                {
                    ll temp=s;
                    for(int h=0;h<k;h++)
                    {
                        if(p&(1<<h))temp+=x[h];
                        else temp-=x[h];
                    }
                    //cout<<"**"<<temp<<endl;
                    mw[p]=max(mw[p],temp);//求出每种情况下主武器的最大值;
                }
            }
            for(int i=0;i<m;i++)
            {
                ll s;
                scanf("%lld",&s);
                for(int j=0;j<k;j++)scanf("%lld",&x[j]);
                for(int p=0;p<len;p++)
                {
                    ll temp=s;
                    for(int h=0;h<k;h++)
                    {
                        if(p&(1<<h))temp+=x[h];
                        else temp-=x[h];
                    }
                    //cout<<"@@"<<temp<<endl;
                    sw[p]=max(sw[p],temp);//求出每种情况下服务器的最大值
                }
            }
            int i,j;
            ll ans=-0x3f3f3f3f;
            for(i=0,j=len-1;i<len&&j>=0;i++,j--)
            {
                ans=max(ans,mw[i]+sw[j]);
            }
            printf("%lld\n",ans);
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37378303/article/details/81987125
今日推荐