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 ...
随机推荐
- SpringBoot | 第二十章:异步开发之异步请求
前言 关于web开发的相关知识点,后续有补充时再开续写了.比如webService服务.发邮件等,这些一般上觉得不完全属于web开发方面的,而且目前webService作为一个接口来提供服务的机会应该 ...
- Linux下安装软件遇见的问题汇总
1.安装monodevelop 安装环境Linux Mint17.1 在软件在中心直接安装monodevelop,安装完成后直接启动界面“一闪而过”,解决办法: 软件中心安装 mono-complet ...
- SpringMVC 返回实体对象时屏蔽某些属性
SpringMVC 可以直接已JSON的结果返回实体对象,可是返回时是所有属性与属性值都会一并返回, 怎样才能屏蔽某些属性?方法很简单,只要在实体对象类中要屏蔽的属性值上加 @JsonIgnore 注 ...
- 网页title旁边的小图片
网页title旁边的小图片设置,图片格式必须是.ico <link rel="icon" href="img/logo.ico" type="i ...
- Linux常用操作2
第1章 find命令扩展 转自:https://www.cnblogs.com/clsn/p/7520333.html 1.1 方法一 |xargs 通过|xargs将前面命令的执行结果传给后面. [ ...
- css动画-小球撞壁反弹
小球碰到一面壁之后一般都会反弹,反射角=入射角: 其实用css3来实现这个效果也非常简单. 首先,分解一下小球的运动:水平运动和垂直运动. 当小球往右下方向运动时,如果碰到了下面的壁,那么由于碰撞,小 ...
- C++ int转string / string转int
c++ 最近标准添加了stringstream类,可以非常简单的对int 和 string 进行相互的转化 //int 转 string void int2str(const int& i, ...
- 【Mood-14】龙虎榜 活跃在github中的1000位中国开发者
Last cache created on 2015-01-07 by Github API v3. ♥ made by hzlzh just for fun. Rank Gravatar usern ...
- 数据字典的设计--4.DOM对象的ajax应用
需求:点击下拉选项框,选择一个数据类型,在表单中自动显示该类型下所有的数据项的名称,即数据库中同一keyword对应的所有不重复的ddlName. 1.在dictionaryIndex.js ...
- 部署JavaWeb时出现 If a file is locked,you can wait until
在部署JavaWeb程序时出现了if a file is locked ,you can wait until the lock stop的问题,这个主要是classpath目录出错或者jar包未导入 ...