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 ...
随机推荐
- springBoot支持PageHelp插件使用学习笔记
首先在springboot项目的maven中加入依赖(版本可能需要自己选择合适的) <dependency> <groupId>com.github.pagehelper< ...
- mysql数据库设置外键,更新与删除选项
CASCADE:父表delete.update的时候,子表会delete.update掉关联记录:SET NULL:父表delete.update的时候,子表会将关联记录的外键字段所在列设为null, ...
- Linux CentOS 7的图形界面安装
1.首先安装X(X Window System) yum groupinstall "X Window System" 2.由于这个软件组比较大,安装过程会比较慢,安装完成后会出现 ...
- linux上面安装svn步骤
一.安装 使用yum,非常简单 yum install subversion 二.配置 2.1.创建仓库 我们这里在/home下建立一个名为svn的仓库(repository),以后所有代码都放在这个 ...
- ln -s 软链接产生Too many levels of symbolic links错误
不能使用相对路径, ln -s ./cmake /usr/bin/ 而是要 ln -s /usr/local/bin/cmake /usr/bin/
- dialog BLE SDK 学习(3)
dialog DA14580 SDK版本:5.0.4. 本文介绍了DA14580 SDK的学习感想和建议,分享给大家. 首先,Dialog官网上的资料挺全的,但是是英文的,如果英文不好,比如笔者,阅读 ...
- 队列--数据结构与算法JavaScript描述(5)
队列 Queue 概念 队列是一种列表,但队列只能在队尾插入元,在队首删除元素. 队列是一种先进先出的数据结构,用于存储按顺序排列的数据,被用在很多地方,比如提交操作系统执行的一系列进程.打印任务池等 ...
- 24-webhost的配置
1-新建asp.net core空项目 2-创建setting.json文件 3- 配制Progrom类中CreateWebHostBuilder 4-获取配置的文件 5-显示结果
- 笔记-python -asynio
笔记-python -asynio 1. 简介 asyncio是做什么的? asyncio is a library to write concurrent code using the a ...
- IAR配置ICF到项目的实现方法
以STM8为例: 将项目使用的MCU型号的icf文件拷贝到项目里面,icf一般放在 C:\Program Files\IAR Systems\Embedded Workbench 6.5\stm8\c ...