列表

详情


NC205074. GameStrategy

描述


Alice, Bob and Cindy are playing an interesting game, each of them has an array of n integers. Each of them will remove an integer of his/her anrry in his/her turn, Alice plays first, Bob second, finally Cindy. In the end, everyone will have only one integer, Alice has x, Bob has y, and Cindy has z. And they will compute the value:


Alice wants to maximize the value, Bob wants to minimize the value, and Cindy wants to make the value be close to zero as possible. Cindy will choose the largest one if there are more than one answers. Everyone is smart enough, so that they will take the best strategy, what will be the final value?


输入描述

The 1st line contains an integer .

The 2nd line contains n integers .

The 3rd line contains n integers .

The 4th line contains n integers .

输出描述

Output the final value.

示例1

输入:

2
1 2
-5 6
3 -10

输出:

-2

说明:

In the case above,Alice will remove 1, Bob removes -5, and Cindy removes 3.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 6ms, 内存消耗: 488K, 提交时间: 2020-04-26 14:26:18

#include<bits/stdc++.h>
typedef long long ll;
const int mod=1e9+7;
const int maxn=1e5+5;
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
int main()
{
	int n;
	cin>>n;
	int a[105],b[105],c[105];
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	for(int i=0;i<n;i++)cin>>c[i];
	int ans=-inf;
	int minn,cnt;
	for(int i=0;i<n;i++){
	     minn=inf;
		for(int j=0;j<n;j++){
			 cnt=inf;
			for(int k=0;k<n;k++){
				if(abs(a[i]+b[j]+c[k])<abs(cnt)){
					cnt=a[i]+b[j]+c[k];
				}else if(abs(a[i]+b[j]+c[k])==abs(cnt)){
					cnt=max(a[i]+b[j]+c[k],cnt);
				}
			
			}
		minn=min(minn,cnt);
		}
		ans=max(ans,minn);
	}
	cout<<ans<<endl; 
	return 0;
 } 

C(clang 3.9) 解法, 执行用时: 6ms, 内存消耗: 476K, 提交时间: 2020-10-11 19:46:36

#include<stdio.h>
#include<math.h>
int n;
void read(int a[]) {
	for(int i = 0; i < n; i ++) {
		scanf("%d",&a[i]);
	}
}
int main() {
	int a[105],b[105],c[105];
	scanf("%d",&n);
	read(a);read(b);read(c);
	int maxa = -100000005;
	for(int i = 0; i < n; i ++) {
		int minb = 100000005;
		for(int j = 0; j < n; j ++) {
			int ccc = 100000005;
			for(int k = 0; k < n; k ++) {
				if(abs(a[i]+b[j]+c[k])<abs(ccc))
					ccc = a[i]+b[j]+c[k];
			}
			minb = minb > ccc ? ccc : minb;
		}
		maxa = maxa > minb ? maxa : minb;
	}
	printf("%d",maxa);
	return 0;
} 

C++11(clang++ 3.9) 解法, 执行用时: 5ms, 内存消耗: 504K, 提交时间: 2020-04-26 22:03:13

#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
int main() {
	int n;
	cin>>n;
	int a[105],b[105],c[105];
	for(int i=0; i<n; i++)cin>>a[i];
	for(int i=0; i<n; i++)cin>>b[i];
	for(int i=0; i<n; i++)cin>>c[i];
	int ans=-inf;
	int minn,cnt;
	for(int i=0; i<n; i++) {
		minn=inf;
		for(int j=0; j<n; j++) {
			cnt=inf;
			for(int k=0; k<n; k++)
				if(abs(a[i]+b[j]+c[k])<abs(cnt))
					cnt=a[i]+b[j]+c[k];
			minn=min(minn,cnt);
		}
		ans=max(ans,minn);
	}
	cout<<ans<<endl;
	return 0;
}

上一题