題面
平面上有一個壞點,在不包含壞點的情況下找最大矩形
平面長寬 <= 104
分析
不難推測,最大的矩形一定與壞點相鄰(受到壞塊制約)
與壞點相鄰的矩形有4種,取最大值即可。
圓圈代表壞區,上下左右四個矩形其餘邊都是原平面的邊界。
當圓圈本身在邊界時,周圍有矩形的面積會變成0,這不影響我們取max
代碼
#include <stdio.h>
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
int maxx(int a, int b, int c, int d)
{
return max(max(a, b), max(c, d));
}
int main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
int a, b, px, py;
int l=0, r=0, u=0, d=0;//上下左右四個面積
for (int o = 0; o < t; o++)
{
cin >> a>>b>>px>>py;
u = a * (py);
d = a * (b - 1 - py);
l = b * (px);
r = b * (a - 1 - px);
cout << maxx(l, r, u, d) << endl;
}
return 0;
}