cf462 A Compatible Pair
2018-02-16 12:47
633 查看
暴力直接找max
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.
InputThe 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.
OutputPrint a single integer — the brightness of the chosen pair.
ExamplesInput
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1<
4000
/span> from himself.
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define f(i,l,r) for(int i=l;i<=r;i++)
#define g(i,l,r) for(int i=l;i>=r;i--)
const int maxn = 2505;
ll a[maxn],b[maxn],c[maxn];
ll n,m ;
int main()
{
cin>>n>>m;
f(i,1,n)cin>>a[i];
f(i,1,m)cin>>b[i];
ll ans = -1000001;
ll t ;
f(i,1,n) f(j,1,m)
{
if(ans<a[i]*b[j])
{
ans=a[i]*b[j];
t= i;
}
}
ans = -1000001;
f(i,1,n)
{
if(i==t)continue;
f(j,1,m)
{
if(ans<a[i]*b[j])
{
ans=a[i]*b[j];
}
}
}
cout<<ans<<endl;
}未来的我一定会感谢现在正在成长的我
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.
InputThe 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.
OutputPrint a single integer — the brightness of the chosen pair.
ExamplesInput
2 2 20 18 2 14Output
252Input
5 3 -1 0 1 2 3 -1 0 1Output
2NoteIn 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<
4000
/span> from himself.
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define f(i,l,r) for(int i=l;i<=r;i++)
#define g(i,l,r) for(int i=l;i>=r;i--)
const int maxn = 2505;
ll a[maxn],b[maxn],c[maxn];
ll n,m ;
int main()
{
cin>>n>>m;
f(i,1,n)cin>>a[i];
f(i,1,m)cin>>b[i];
ll ans = -1000001;
ll t ;
f(i,1,n) f(j,1,m)
{
if(ans<a[i]*b[j])
{
ans=a[i]*b[j];
t= i;
}
}
ans = -1000001;
f(i,1,n)
{
if(i==t)continue;
f(j,1,m)
{
if(ans<a[i]*b[j])
{
ans=a[i]*b[j];
}
}
}
cout<<ans<<endl;
}未来的我一定会感谢现在正在成长的我
相关文章推荐
- cf462 A Compatible Pair
- Codeforces Round #462 (Div. 2) A. A Compatible Pair
- Codeforces Round #462 (Div. 2) A Compatible Pair
- 【Codeforces Round #462 (Div. 2)】A - A Compatible Pair
- codeforces934 A. A Compatible Pair【暴力】
- Codeforces 934.A A Compatible Pair
- 934A A Compatible Pair
- cf 934 A Compatible Pair
- CodeForces 934A A Compatible Pair
- Perl Regex: Extract Key Value Pair
- 【代码保留】成对值类(PairCollection和Pair)
- SetCompatibleTextRenderingDefault的作用是什么?
- CreateCompatibleDC(HDC hdc);
- make_pair
- JSON--就是名值对 name/value pair
- (Microsoft.Reporting.WebForms.ReportViewer) is not compatible with the type of control (Microsoft.Reporting.WebForms.ReportViewer)
- C# KeyValuePair 的基本用法及结合泛型的用法
- java.lang.IncompatibleClassChangeError
- 使用META的 X-UA-Compatible 设置网页兼容模式(转)
- Air Jordan to be discovered by people who have this pair of shoes!