Codeforces Round #462 (Div. 2) A Compatible Pair
A. A Compatible Pair
time limit per test1 second
memory limit per test256 megabytes
Problem Description
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has n lanterns and Big Banban has m lanterns. Tommy’s lanterns have brightness a1, a2, …, an, and Banban’s have brightness b1, b2, …, bm respectively.
Tommy intends to hide one of his lanterns, then Banban picks one of Tommy’s non-hidden lanterns and one of his own lanterns to form a pair. The pair’s brightness will be the product of the brightness of two lanterns.
Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.
You are asked to find the brightness of the chosen pair if both of them choose optimally.
Input
The first line contains two space-separated integers n and m (2 ≤ n, m ≤ 50).
The second line contains n space-separated integers a1, a2, …, an.
The third line contains m space-separated integers b1, b2, …, bm.
All the integers range from - 109 to 109.
Output
Print a single integer — the brightness of the chosen pair.
Examples
input
2 2
20 18
2 14
output
252
input
5 3
-1 0 1 2 3
-1 0 1
output
2
Note
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
解题心得:
- 题意很简单就是给你两个数列a和b,要求你在a中选一个数b中选一个数两数的乘积最大,但是a为了使乘积尽量小会删去一个数,要求你输出除a删去了那个数之后能够的到的乘积最大的那个数。
- 数据范围很小也就50,可以先找出乘积最大的z中的那个数,然后标记,在找标记之后最大的就行了。暴力最稳妥。
代码写得很烂,切勿模仿
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 55;
ll n,m;
ll a[maxn],b[maxn];
map <ll,ll> maps;
struct NODE{
ll x,y,va;
friend bool operator < (const NODE a,const NODE b){
return a.va < b.va;
}
};
int main() {
priority_queue <NODE> qu;
scanf("%lld%lld", &n, &m);
for (int i = 0; i < n; i++)
scanf("%lld", &a[i]);
for (int i = 0; i < m; i++)
scanf("%lld", &b[i]);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
NODE temp;
long long c = a[i]*b[j];
temp.x = i;
temp.y = j;
temp.va = c;
qu.push(temp);
}
bool flag = false;
while(!qu.empty()){
NODE temp = qu.top();
qu.pop();
if(!flag){
maps[temp.x] = 233;
flag = true;
}
if(maps[temp.x] != 233){
printf("%lld",temp.va);
break;
}
}
return 0;
}
Codeforces Round #462 (Div. 2) A Compatible Pair的更多相关文章
- Codeforces Round #188 (Div. 2) C. Perfect Pair 数学
B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...
- Codeforces Round #462 (Div. 2) B-A Prosperous Lot
B. A Prosperous Lot time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #462 (Div. 2), problem: (C) A Twisty Movement (求可以转一次区间的不递增子序列元素只有1,2)
题目意思: 给长度为n(n<=2000)的数字串,数字只能为1或者2,可以将其中一段区间[l,r]翻转,求翻转后的最长非递减子序列长度. 题解:求出1的前缀和,2的后缀和,以及区间[i,j]的最 ...
- Codeforces Round #462 (Div. 2) C DP
C. A Twisty Movement time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #462 (Div. 2)
这是我打的第三场cf,个人的表现还是有点不成熟.暴露出了我的一些问题. 先打开A题,大概3min看懂题意+一小会儿的思考后开始码代码.一开始想着贪心地只取两个端点的值就好了,正准备交的时候回想起上次A ...
- Codeforces Round #462 (Div. 2) D. A Determined Cleanup
D. A Determined Cleanup time limit per test1 second memory limit per test256 megabytes Problem Descr ...
- Codeforces Round #462 (Div. 2) C. A Twisty Movement
C. A Twisty Movement time limit per test1 second memory limit per test256 megabytes Problem Descript ...
- 【Codeforces Round #462 (Div. 1) B】A Determined Cleanup
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 设\(设f(x)=a_d*x^{d}+a_{d-1}*x^{d-1}+...+a_1*x+a_0\) 用它去除x+k 用多项式除法除 ...
- 【Codeforces Round #462 (Div. 1) A】 A Twisty Movement
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] ans初值值为a[1..n]中1的个数. 接下来考虑以2为结尾的最长上升子序列的个数. 枚举中间点i. 计算1..i-1中1的个数c ...
随机推荐
- Java学习笔记--继承和多态(上)
1.通过继承来开发超类(superclass) 2.使用super 关键词唤起超类的构造方法 3.在超类中覆盖方法 4.区分override和overload 5.在Object类中探索toStrin ...
- java多线程处理任务
最近用到使用多线程处理给用户发送站内消息的问题,想到使用java自带的线程池进行处理这个问题,具体如下: 定义一个线程: package com.qlwb.util; import org.apach ...
- 关于Mdi窗口-父窗口上的控件把子窗口的挡住的问题
using System.Runtime.InteropServices; [DllImport("user32")] public static extern int SetPa ...
- spring batch 以游标的方式 数据库读取数据 然后写入目标数据库
前面关于Spring Batch的文章,讲述了SpringBatch对Flat.XML等文件的读写操作,本文将和大家一起讨论Spring Batch对DB的读写操作.Spring Batch对DB数据 ...
- Java集合框架—Map
Map集合:该集合存储键值对.一对一对往里存.而且要保证键的唯一性. 1,添加. put(K key, V value) putAll(Map<? extends K,? extends V& ...
- Android 在已有工程中实现微信图片压缩
这个我们需要自己去编译,但是已经有人帮我们编译好了,压缩算法也已经实现,因此,我们去下载然后编译即可:https://github.com/bither/bither-android-lib 首先将上 ...
- 优化Linux的内核参数来提高服务器并发处理能力
提高Linux系统下的负载能力,可以使用nginx等原生并发处理能力就很强的web服务器 使用Apache的可以启用其Worker模式,来提高其并发处理能力 修改Linux的内核相关TCP参数,来最大 ...
- JFinal常量配置学习笔记
在继承 JFinalConfig 类时,需要 实现 /** * Config constant */ public abstract void configConstant(Constants me) ...
- codevs 2620 战壕
时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold 题目描述 Description Smart和Sarah正在玩一个即时战略游戏. Smart在他的基地附近建立了n个 ...
- 制作X509证书
makecert -r -pe -n "CN=XXX" -b 01/01/2005 -e 01/01/2020 -sky exchange -ss my