题目相关
题目链接
AtCoder Beginner Contest 178 B 题,https://atcoder.jp/contests/abc178/tasks/abc178_b。
Problem Statement
Given are integers a,b,c and d. If x and y are integers and a≤x≤b and c≤y≤d hold, what is the maximum possible value of x×y?
Input
Input is given from Standard Input in the following format:
a b c d
Output
Print the answer.
Samples1
Sample Input 1
1 2 1 1
Sample Output 1
2
Explaination
If x=1 and y=1 then x×y=1. If x=2 and y=1 then x×y=2. Therefore, the answer is 2.
Samples2
Sample Input 2
3 5 -4 -2
Sample Output 2
-6
Samples3
Sample Input 3
-1000000000 0 -1000000000 0
Sample Output 3
1000000000000000000
Constraints
- All values in input are integers.
题解报告
AtCoder 的 A 和 B 都是非常简单的题目,适合初学者。难度在于英文的理解能力上。
题目翻译
给定四个整数 a、b、c 和 d,现在有两个整数 x ()和 y()。问 的最大值是多少?
题目分析
求 的最大值,而且 x 和 y 没有相关性,那么,只需要根据 x 和 y 的独立情况进行分类讨论即可。注意到 x 和 y 可能出现负数,使用分类讨论方法,需要特别仔细的分类。
换一个思路来看,我们求的最大值,因此只能出现在 a、b、c 和 d 这四个数字的乘积组合上。也就是说,最大值只能是 a*c、a*d、b*c 或者 b*d 这四个数中的一个。这样,问题就变成在四个数中找最大值。
AC 参考代码
//https://atcoder.jp/contests/abc178/tasks/abc178_b
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a,b,c,d;
cin>>a>>b>>c>>d;
long long ans;
ans=max(a*c, a*d);
ans=max(ans, b*c);
ans=max(ans, b*d);
cout<<ans<<"\n";
return 0;
}