【习题 8-19 UVA-1312】Cricket Field
【链接】 我是链接,点我呀:)
【题意】
【题解】
添加两个y坐标0和h 然后从这n+2个y坐标中任选两个坐标,作为矩形的上下界。然后看看哪些点在这个上下界中。
定义为坐标集合S
S中的点的相邻x坐标差和上下界的差的较小值是这个矩形能够构成的最大正方形。
枚举所有情况就好。
【代码】
#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1
using namespace std;
const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N = 100;
int n,w,h,px,py,anslen;
pair<int,int> a[N+10];
bool cmp(pair<int,int> x,pair<int,int> y){
return x.first<y.first;
}
void solve(){
anslen = -1;
cin >> n >> w >> h;
for (int i = 1;i <= n;i++)
cin >> a[i].first>>a[i].second;
sort(a+1,a+1+n);
a[0].second = 0;a[n+1].second = h;
a[n+1].first = w;
for (int i = 0;i <= n+1;i++){
for (int j = 0;j <= n+1;j++){
int upy = max(a[i].second,a[j].second),downy = min(a[i].second,a[j].second);
int len = upy-downy;
int prex = 0;
for (int k = 1;k <= n+1;k++){
if (k==n+1||(downy<a[k].second && a[k].second<upy)){
int templen = min(len,a[k].first-prex);
if (templen>0){
if (anslen==-1 || templen>anslen){
anslen = templen;
px = prex,py = downy;
}
}
prex = a[k].first;
}
}
}
}
cout<<px<<' '<<py<<' '<<anslen<<endl;
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int T;
cin >> T;
int kase = 0;
while(T--){
if (kase==0)
kase++;
else
cout<<endl;
solve();
}
return 0;
}