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分别代表有n种主武器,m种副武器,每把武器都有k种属性,接下来n,m行有k+1个数,第一数代表该武器的总S,接下来k个数分别代表其属性指,让你选择一把主武器和副武器使得最大
解题思路:
其中的求和是取绝对值,那每个武器的属性都可能做正贡献或者做负贡献,那么每个武器的贡献就是S加加减减武器的值,其中Sn和Sm的加减是相对的,如果Sn是加的话那Sm就是减,那我们就可以枚举2^k次情况维护最大值(因为K的值小于5,所以时间复杂度并不是很高)
ACcode:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f3f
#define MAXN 100005
struct wea{
int K[6];
LL S;
}mai[MAXN],sec[MAXN];
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n,m,k;
scanf("%d %d %d",&n,&m,&k);
for(int i=0;i<n;i++){
scanf("%d",&mai[i].S);
for(int j=0;j<k;j++){
scanf("%d",&mai[i].K[j]);
}
}
for(int i=0;i<m;i++){
scanf("%d",&sec[i].S);
for(int j=0;j<k;j++){
scanf("%d",&sec[i].K[j]);
}
}
int ss=1<<k; //枚举2^k次
LL mx1,mx2,ans;
ans=-INF;
for(int i=0;i<ss;i++){
mx1=-INF;
for(int j=0;j<n;j++){
LL temp=mai[j].S;
for(int kk=0;kk<k;kk++){
if((1<<kk)&i)temp+=mai[j].K[kk]; //相对的加加减减
else temp-=mai[j].K[kk];
}
mx1=max(mx1,temp); //记录该情况下的最大值
}
mx2=-INF;
for(int j=0;j<m;j++){
LL temp=sec[j].S;
for(int kk=0;kk<k;kk++){
if((1<<kk)&i)temp-=sec[j].K[kk];
else temp+=sec[j].K[kk];
}
mx2=max(mx2,temp);
}
ans=max(ans,mx1+mx2); //记录答案的最大值
}
printf("%lld\n",ans);
}
}