1. 程式人生 > >HDU 6345 Problem J. CSGO(思路)

HDU 6345 Problem J. CSGO(思路)

Problem J. CSGO
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 571 Accepted Submission(s): 301

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個副屬性,問選一個主武器和一個副武器可以獲得的最大屬性值,最大屬性值的定義為:主武器的主屬性+副武器的主屬性+主武器每個副屬性和副武器對應副屬性 差值的絕對值

分析:
當選擇一個主武器和副武器時,可以獲得的屬性值為 |wxiwyi|,分析這個條件,發現每個屬性對答案的貢獻肯定為一加一減的形式
(1)wxi比較大,wyi比較小,前加後減
(2)wxi比較小,wyi比較大,前減後加
知道了這些就比較簡單了
由於k比較小,那麼可以列舉k位二進位制
對主武器來說 0表示減,1表示加,副武器則相反
然後對每個二進位制狀態遍歷主武器和伺服器的屬性值,求出最大貢獻,加起來重新整理答案即可

#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int N=1e5+200;

typedef long long LL;
const LL INF=1e12;
int a[N][7],b[N][7];
int main()
{
    int kcase,n,m,k;
    scanf("%d",&kcase);
    while(kcase--)
    {
        scanf("%d%d%d",&n,&m,&k);
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i][k]);
            for(int j=0; j<k; j++)scanf("%d",&a[i][j]);
        }
        for(int i=1; i<=m; i++)
        {
            scanf("%d",&b[i][k]);
            for(int j=0; j<k; j++)scanf("%d",&b[i][j]);
        }
        LL ans=0;
        for(int i=0; i<(1<<k); i++)
        {
            LL max1=-INF,max2=-INF;
            for(int j=1; j<=n; j++)
            {
                LL cnt=a[j][k];
                for(int t=0; t<k; t++)
                {
                    if(i&(1<<t))
                        cnt+=a[j][t];
                    else
                        cnt-=a[j][t];
                }
                max1=max(max1,cnt);
            }
            for(int j=1;j<=m;j++)
            {
                LL cnt=b[j][k];
                for(int t=0;t<k;t++)
                {
                    if(i&(1<<t))
                        cnt-=b[j][t];
                    else
                        cnt+=b[j][t];
                }
                max2=max(max2,cnt);
            }
            ans=max(ans,max1+max2);
        }
        printf("%lld\n",ans);
    }
    return 0;
}