B从由两个数列中各挑出一个数相乘,他想让乘积最大化,A想让乘积最小化,他可以抹去一个数。求最终B得到的乘积
场上疯狂hack...
由于数据十分的小,我当时直接暴力求解A要抹去的数,然后再暴力求乘积即可。。。
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define INF 0x3f3f3f3f using namespace std; typedef long long LL; const int maxn = 60; int N, M; LL A[maxn], B[maxn]; int main() { scanf("%d%d", &N, &M); for (int i = 1; i <= N; i++) { scanf("%lld", &A[i]); } for (int i = 1; i <= M; i++) { scanf("%lld", &B[i]); } LL I = -1000000000000000001; LL tmp = I; int flag = 1; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) { LL t = A[i] * B[j]; if (t > tmp) { tmp = t; flag = i; } } } tmp = I; for (int i = 1; i <= N; i++) { if (i == flag) continue; for (int j = 1; j <= M; j++) { LL t = A[i] * B[j]; if (t > tmp) { tmp = t; } } } printf("%lld ", tmp); return 0; }