Codeforces 934.A A Compatible Pair
1 second
256 megabytes
standard input
standard output
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.
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.
Print a single integer — the brightness of the chosen pair.
2 2
20 18
2 14
252
5 3
-1 0 1 2 3
-1 0 1
2
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.
题目大意:Tommy有n个数,Banban有m个数,Tommy会选择自己的一个数隐藏起来,Banban会选择自己的一个数和Tommy的一个没有隐藏的数相乘,Tommy想让结果最小,Banban想让结果最大,问最后的结果是什么.
分析:这题坑啊.以为只用判断两个端点的情况的,结果没想到有负数.
这道题的话一个三重循环就能搞定.枚举隐藏哪一个数,将之后所得的乘积排个序,取第二大的就是答案.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll; int n,m;
ll a[],b[],c[],tot,ans = ; int main()
{
scanf("%d%d",&n,&m);
for (int i = ; i <= n; i++)
cin >> a[i];
for (int i = ; i <= m; i++)
cin >> b[i];
for (int i = ; i <= n; i++)
{
tot = ;
for (int j = ; j <= n; j++)
{
if (j == i)
continue;
for (int k = ; k <= m; k++)
c[++tot] = a[j] * b[k];
}
sort(c + ,c + tot + );
ans = min(ans,c[tot]);
}
cout << ans << endl; return ;
}
Codeforces 934.A A Compatible Pair的更多相关文章
- Codeforces 934 A.Compatible Pair
http://codeforces.com/contest/934 A. A Compatible Pair time limit per test 1 second memory limit p ...
- Codeforces Round #462 (Div. 2) A Compatible Pair
A. A Compatible Pair time limit per test1 second memory limit per test256 megabytes Problem Descript ...
- 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 ...
- Codeforces 934 最长不递减子序列 多项式系数推导
A B C 给你一个长度为N的01串 你可以翻转一次任意[L,R]的区间 问你最长的不递减序列为多少长 处理出1的前缀和 和2的后缀和 然后N^2 DP 处理出 [L,R]区间的最长不递增序列 #in ...
- 题解 CF934A 【A Compatible Pair】 ——贪心
题意: 给定两个数列 \(A\) . \(B\) ,元素个数分别为 \(n\) , \(m\) \((2 \le n,m \le 50)\) .数列中所有元素大小均在 \(-10^{9}\) 到 \( ...
- Codeforces 934.C A Twisty Movement
C. A Twisty Movement time limit per test 1 second memory limit per test 256 megabytes input standard ...
- A Compatible Pair
Description “年”是一个生活在海洋深处的怪物.每年,它都出现在陆地上,吞噬牲畜甚至是人.为了让怪物离开,人们用红色,光线和爆炸的声音填满他们的村庄,所有这些都吓跑了怪物. 小汤米有 n ...
- Codeforces 934.D A Determined Cleanup
D. A Determined Cleanup time limit per test 1 second memory limit per test 256 megabytes input stand ...
随机推荐
- 使用windows api安装windows服务程序(C#)
3个步骤: 1.安装器代码编写 2.安装器工具类编写 1)安装.启动服务) 2)卸载服务 3.windows服务程序编写(参考:多线程.方便扩展的Windows服务程序框架) 4.代码下载,在文末(注 ...
- 《算法》第四版 IDEA 运行环境的搭建
<算法>第四版 IDEA 运行环境的搭建 新建 模板 小书匠 在搭建之初,我是想不到会出现如此之多的问题.我看了网上的大部分教程,都是基于Eclipse搭建的,还没有使用IDEA搭建的教程 ...
- 将Komodo Edit打造成Python开发的IDE
Komodo Edit 支持Python 界面清爽, 将Komodo Edit 设置成Python的IDE,具体操作方法如下: 先添加自定义命令. 再设置命令行参数 设置高级选项 设置快捷键 完成.
- 笔记-git-git服务器安装及配置
笔记-git-git服务器安装及配置 1. GIT服务器简介 Git 可以使用四种主要的协议来传输数据:本地传输,SSH 协议,Git 协议和 HTTP 协议.下面分别介绍一下哪些情形应该使 ...
- CentOS 使用 LAMP 环境开启 SSL 搭建 WordPress
环境阿里云新装CentOS 7.4, 使用yum(非编译安装)搭建LAMP, CA证书为阿里云免费提供的, WordPress为官网下载 安装 LAMP 并开启 HTTPS 1, 关闭防火墙 # sy ...
- Java实现系统目录实时监听更新。
SDK1.7新增的nio WatchService能完美解决这个问题.美中不足是如果部署在window系统下会出现莫名其妙的文件夹占用异常导致子目录监听失效,linux下则完美运行.这个问题着实让人头 ...
- 「微信小程序免费辅导教程」26,基础内容组件rich-text体验
- Docker容器 - 容器时间跟宿主机时间同步
在Docker容器创建好之后,可能会发现容器时间跟宿主机时间不一致,这就需要同步它们的时间,让容器时间跟宿主机时间保持一致. 转载自:https://www.cnblogs.com/kevingrac ...
- luogu3317 [SDOI2014]重建
原来矩阵树定理对于边是概率的情况也是适用的qwqwq. ref #include <iostream> #include <cstdio> #include <cmath ...
- Spark Streaming实例
Spark Streaming实例分析 2015-02-02 21:00 4343人阅读 评论(0) 收藏 举报 分类: spark(11) 转载地址:http://www.aboutyun.co ...