NC205074. GameStrategy
描述
输入描述
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; }