Codeforces-462A. A Compatible Pair
阿新 • • 發佈:2018-02-15
直接 can .com targe lan using air iostream div
傳送門
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 (inti = 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\n", tmp); return 0; }
Codeforces-462A. A Compatible Pair