#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n,t,x,y,z,r,kase = 0;
const int maxn = 4*1e6+10;
double sumx,sumy;
struct point {
double x,y;
point(double a=0,double b=0):x(a),y(b){}
bool operator < (const point &b) const {
return x < b.x || (x == b.x && y < b.y);
}
}p[maxn],ch[maxn];
point operator - (point a,point b) { return point(a.x-b.x,a.y-b.y); }
double cross(point a,point b) { return a.x*b.y-a.y*b.x; }
int convexhull(point *p,int n,point *ch) {
int m = 0;
sort(p,p+n);
for (int i = 0; i < n; i++) {
while(m > 1 && cross(ch[m-1]-ch[m-2],p[i]-ch[m-2]) <= 0) m--;
ch[m++] = p[i];
}
int k = m;
for (int i = n-2; i >= 0; i--) {
while(m > k && cross(ch[m-1]-ch[m-2],p[i]-ch[m-2]) <= 0) m--;
ch[m++] = p[i];
}
if (n > 1) m--;
return m;
}
int dist(point a,point b) {
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int getMaxDirmater(point *p,int m) {
if (m == 1) return 0;
if (m == 2) return dist(ch[0],ch[1]);
int ans = 0;
for (int u = 0, v= 1; u < m; u++) {
for (;;) {
int diff = cross(p[(u+1)%m]-p[u],p[(v+1)%m]-p[v]);
if (diff <= 0) {
ans = max(ans,dist(p[u],p[v]));
if (diff == 0) {
ans = max(ans,dist(p[u],p[v+1]));
}
break;
}
v = (v+1)%m;
}
}
return ans;
}
int main()
{
scanf ("%d",&t);
while(t--) {
n = 0;
scanf ("%d",&r);
for (int i = 1; i <= r; i++) {
scanf ("%d%d%d",&x,&y,&z);
p[n++] = point(x,y);
p[n++] = point(x,y+z);
p[n++] = point(x+z,y);
p[n++] = point(x+z,y+z);
}
int m = convexhull(p,n,ch);
printf ("%d\n", getMaxDirmater(ch,m));
}
return 0;
}
旋转卡壳LA4728
最新推荐文章于 2019-09-18 16:47:21 发布