A - A Compatible Pair-biaobiao88
A - A Compatible Pair
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
2 2
20 18
2 14
252
5 3
-1 0 1 2 3
-1 0 1
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.
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long long cmp(long long x,long long y)
{
return x > y;
} int main()
{
long long a[],b[],c[],n,m;
cin >> n >> m;
if(n >= && m <= )
{
for(int i = ;i < n;i++)
cin >> a[i];
for(int i = ;i < m;i++)
cin >> b[i];
sort(a,a + n,cmp);
sort(b,b + m,cmp);
for(int i = ;i < n;i++)
{
c[i] = a[i] * b[];
for(int j = ;j < m;j++)
{
c[i] = max(c[i],a[i] * b[j]);
}
}
sort(c,c + n,cmp);
cout << c[] << endl;
// for(int i = 0;i < n;i++)
// cout << a[i] << " ";
// cout << endl;
// for(int i = 0;i < m;i++)
// cout << b[i] << " ";
}
return ;
}
排除出一个最大值的就ok了
A - A Compatible Pair-biaobiao88的更多相关文章
- Codeforces 934.A A Compatible Pair
A. A Compatible Pair time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #462 (Div. 2) A Compatible Pair
A. A Compatible Pair time limit per test1 second memory limit per test256 megabytes Problem Descript ...
- Codeforces 934 A.Compatible Pair
http://codeforces.com/contest/934 A. A Compatible Pair time limit per test 1 second memory limit p ...
- CF934A A Compatible Pair
A Compatible Pair time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- A - A Compatible Pair
Problem description Nian is a monster which lives deep in the oceans. Once a year, it shows up on th ...
- 题解 CF934A 【A Compatible Pair】 ——贪心
题意: 给定两个数列 \(A\) . \(B\) ,元素个数分别为 \(n\) , \(m\) \((2 \le n,m \le 50)\) .数列中所有元素大小均在 \(-10^{9}\) 到 \( ...
- A Compatible Pair
Description “年”是一个生活在海洋深处的怪物.每年,它都出现在陆地上,吞噬牲畜甚至是人.为了让怪物离开,人们用红色,光线和爆炸的声音填满他们的村庄,所有这些都吓跑了怪物. 小汤米有 n ...
- CF934A A Compatible Pair 题解
Content 有两个数列 \(A\) 和 \(B\),\(A\) 数列里面有 \(n\) 个元素,\(B\) 数列里面有 \(m\) 个元素,现在请从 \(A\) 数列中删除一个数,使得 \(A\) ...
- pair queue____多源图广搜
.简介 class pair ,中文译为对组,可以将两个值视为一个单元.对于map和multimap,就是用pairs来管理value/key的成对元素.任何函数需要回传两个值,也需要pair. 该函 ...
随机推荐
- ObjectARX之Mac os开发
网上关于ObjectARX开发的相关介绍都基于Windows环境.Mac 环境的开发几乎没有,下面介绍Mac环境下ObjectARX的开发. AutoCAD ObjectARX开发必备条件: 1. 安 ...
- python爬虫(5)——BeautifulSoup & docker基础
BeautifulSoup基础实战 安装:pip install beautifulsoup4 常用指令: from bs4 import BeautifulSoup as bs import url ...
- Docker--部署mongodb+.netcore+nginx
前言 公司租用的阿里云的服务器,每年会更换一次,很麻烦,还容易出问题,想会不会有更方便的方式来迁移服务器,就这样接触到了docker. 参考网上的一些资料,自己琢磨了一段时间,记录下docker的部署 ...
- JS高阶---函数
[问题] [主体] 1.什么是函数? ①实现特定功能 ②多条语句的封装体 ③可以重复执行的代码块 2.为什么用函数? 提高代码的复用性,提升效率 3.如何定义函数? ①函数声明定义 ②函数表达式定义③ ...
- USB摄像头驱动框架分析
usb摄像头驱动程序,里面涉及硬件的操作.比如说,想设置亮度的时候,需要把亮度的参数发给硬件.去得到真正视频数据的时候,需要访问硬件得到数据.usb摄像头驱动程序框架与虚拟摄像头驱动程序的框架是一样的 ...
- 201777010217-金云馨《面向对象程序设计(Java)》第十二周学习总结
内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p/ ...
- jenkins部署报404错误
环境:tomcat 7+jdk1.7+win10 64 jenkins_1.5.23 部署完成后服务器启动输入网址:http://192.168.3.100:8080/jenkins打开无法访问报40 ...
- Python27期:错误宝典
错误信息1:SyntaxError:invalid syntax--无效语法 解决办法:变量名不能使用关键字如下图: 错误信息2:TypeError:'str' object is not calla ...
- MDK快速定位硬件异常位置方法(移植SEGGER_HardFaultHandler库),调用show caller code即可快速锁定(参考硬汉哥)
今天网上看到keil中如果快速定位hardfault的方法参考如下说明:1. MDK的硬件异常分析主要是通过MDK调试状态进行分析的. 文档下载 apnt209.pdf (651 KB, 下载次数: ...
- 不使用xftp上传/下载文件到linux
yum install lrzsz # 安装软件 window端上传到linux端: 1. window端先压缩需上传的文件 2. linux端运行命令rz 3. 在弹出的窗口选择压缩好的文件, ...