码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces-462A. A Compatible Pair

时间:2018-02-14 23:16:33      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:air   problem   个数   log   pac   pair   include   std   lld   

传送门

 

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\n", tmp);
    return 0;
}

 

Codeforces-462A. A Compatible Pair

标签:air   problem   个数   log   pac   pair   include   std   lld   

原文地址:https://www.cnblogs.com/xFANx/p/8449061.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!