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| | w x i − w y i | ,分析这个条件,发现每个属性对答案的贡献肯定为一加一减的形式
(1) wxi w x i 比较大, wyi w y i 比较小,前加后减
(2) wxi w x i 比较小, wyi w y i 比较大,前减后加
知道了这些就比较简单了
由于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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值