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 ...
随机推荐
- linux笔记学习大全,包括相关软件
1.如果tomcat正常启动,内部浏览器可以访问,外部电脑的浏览器布恩那个访问? 可以使用如下命令: iptables -F firewall-cmd --add-port=8080/tcp --pe ...
- android读写SD卡封装的类
参考了网上的一些资源代码,FileUtils.java: package com.example.test; import java.io.BufferedInputStream; import ja ...
- 零基础逆向工程24_C++_01_类_this指针_继承本质_多层继承
1 类内的成员函数和普通函数的对比 1.1 主要是从参数传递.压栈顺序.堆栈平衡来总结. 1.参数传递:成员函数多传一个this指针 2.压栈顺序:成员函数会将this指针压栈,在函数调用取出 3.堆 ...
- MATLAB之数据处理+公式拟合
MATLAB之数据处理+公式拟合 前言:由试验得到一组数据,对该组数据进行处理,作图分析,分析各变量的关系,期望得到拟合公式. 试验数据背景 本次试验有三个自变量:V.M.G,因变量为F,每组试验重复 ...
- PHP中XML和数组互相转换的方法
转换代码如下 //数组转XML function arrayToXml($arr) { $xml = "<xml>"; foreach ($arr as $key=&g ...
- 用xaml画的带阴影3D感的圆球
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center"> <E ...
- C#中Dictionary泛型集合7种常见的用法
要使用Dictionary集合,需要导入C#泛型命名空间 System.Collections.Generic(程序集:mscorlib) Dictionary的描述1.从一组键(Key)到一组值( ...
- 【MATLAB】设定坐标的轴的范围
set(gca,'XLim',[0 1.5]);%X轴的数据显示范围set(gca,'XTick',[0:0.1:1.5]);%设置要显示坐标刻度set(gca,'XTickLabel',[0:0.1 ...
- 命令行启动mysql服务
在<计算机网络>课程中曾学过net命令,可以用于启动后台服务.在mysql中,net命令用于启动后台服务器进程mysqld,即后台服务. 不过,如果在普通用户模式下net start my ...
- jQuery-动画animate() 方法操作 CSS 属性
语法: $(selector).animate({params},speed,callback); 多个params 之间用逗号(,)隔开. 必须使用 Camel 标记法书写所有的属性名,比如,必须使 ...