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个副属性,问选一个主武器和一个副武器可以获得的最大属性值,最大属性值的定义为:主武器的主属性+副武器的主属性+主武器每个副属性和副武器对应副属性 差值的绝对值
分析:
当选择一个主武器和副武器时,可以获得的属性值为 |wxi−wyi| | 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
#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; jscanf("%d",&a[i][j]);
}
for(int i=1; i<=m; i++)
{
scanf("%d",&b[i][k]);
for(int j=0; jscanf("%d",&b[i][j]);
}
LL ans=0;
for(int i=0; i<(1<for(int j=1; j<=n; j++)
{
LL cnt=a[j][k];
for(int t=0; tif(i&(1<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;tif(i&(1<else
cnt+=b[j][t];
}
max2=max(max2,cnt);
}
ans=max(ans,max1+max2);
}
printf("%lld\n",ans);
}
return 0;
}