【Codeforces Round #462 (Div. 2)】A - A Compatible Pair

本文解析了一道算法博弈题,题目涉及两个玩家Tommy和Banban的操作。Tommy从序列A中删除一个元素,Banban从两个序列中选择元素使得乘积最大化。文章提供了一个高效的解决方案,并通过代码实现了该算法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题意:给定序列A和序列B,Tommy从序列A中隐藏(删掉)一个元素, Banban从序列A和B中分别取出一个元素,他们的乘积a[i]*b[j],Tommy尽量使它们小, Banban尽量使它们更大。 求乘积的结果
-10^9<=Ai,Bi<=10^9 , 序列长度n,m范围是[1,50]

分析:被叉得飞起的一题。 自己也被叉了。。
xg.. 可以把所有的乘积结果存起来,排序就好了, 不存起来的 也可以找到次大的结果。。也行。。 蒻苣OoO

Code:

#include <bits/stdc++.h>
using namespace std;

#define mem(a,n) memset(a,n,sizeof(a))
#define memc(a,b) memcpy(a,b,sizeof(b))
#define rep(i,a,n) for(int i=a;i<n;i++) ///[a,n)
#define dec(i,n,a) for(int i=n;i>=a;i--)///[n,a]
#define pb push_back
#define fi first
#define se second
#define IO ios::sync_with_stdio(false)
#define fre freopen("in.txt","r",stdin)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
typedef unsigned long long ull;
const double PI=acos(-1.0);
const double E=2.718281828459045;
const double eps=1e-3;
const int INF=0x3f3f3f3f;
const int MOD=258280327;
const int N=2e3+5;
const ll llinf=1LL<<63-1;
const int dir[4][2]= {-1,0,1,0,0,-1,0,1};
ll ans[N];
int main()
{
    IO;
    ll a[N],b[N];
    int n,m;
    while(cin>>n>>m)
    {
        rep(i,0,n) cin>>a[i];
        rep(i,0,m) cin>>b[i];
        rep(i,0,n)
        {
            ll tmp=-llinf; 
            rep(j,0,m)
            {
                tmp=max(tmp,a[i]*b[j]);
            }
            ans[i]=tmp;
        }
        sort(ans,ans+n);
        cout<<ans[n-2]<<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值