2018 Multi-University Training Contest 10: J. CSGO(思维题)

 

Problem J. CSGO

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

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≤100000,k≤5)

思路:

  1. K≤5!
  2. 那肯定是从k下手,可以发现\small max(|a_i-b_i|)=max(a_i-b_i,b_i-a_i)
  3. 发现上面那个式子那么这道题AC就是迟早的事情了,暴力枚举每个次要属性到底是\small a_i-b_i还是\small b_i-a_i
  4. 如果某个次要属性是\small a_i-b_i,那么将主武器的该次要属性设为正,副武器的该次要属性设为负,然后各求最值相加即可
  5. 总共\small 2^{k}种情况中求出最大值就是答案,复杂度O(32n)

 

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
#define LL long long
#define mod 1000000007
int k, flag[8];
typedef struct Res
{
	LL a[8], val;
	void Add()
	{
		int i;
		val = a[0];
		for(i=1;i<=k;i++)
			val += a[i]*(flag[i]==0?-1:1);
	}
}Res;
Res s1[100005], s2[100005];
int main(void)
{
	LL p1, p2, ans;
	int T, n, m, i, j;
	scanf("%d", &T);
	while(T--)
	{
		scanf("%d%d%d", &n, &m, &k);
		for(i=1;i<=n;i++)
		{
			for(j=0;j<=k;j++)
				scanf("%lld", &s1[i].a[j]);
		}
		for(i=1;i<=m;i++)
		{
			for(j=0;j<=k;j++)
				scanf("%lld", &s2[i].a[j]);
		}
		ans = 0;
		for(i=0;i<(1<<k);i++)
		{
			for(j=0;j<=k-1;j++)
			{
				flag[j+1] = 0;
				if(i&(1<<j))
					flag[j+1] = 1;
			}
			for(j=1;j<=n;j++)
			{
				s1[j].Add();
				if(j==1)
					p1 = s1[j].val;
				p1 = max(p1, s1[j].val);
			}
			for(j=0;j<=k-1;j++)
				flag[j+1] ^= 1;
			for(j=1;j<=m;j++)
			{
				s2[j].Add();
				if(j==1)
					p2 = s2[j].val;
				p2 = max(p2, s2[j].val);
			}
			ans = max(ans, p1+p2);
		}
		printf("%lld\n", ans);
	}
	return 0;
}
/*
10
3 3 2
1 2 3
2 3 4
3 4 5
5 1 6
2 5 4
7 3 5
*/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值