[暴力 乱搞] BZOJ 2338 [HNOI2011]数矩形

枚举对角线,两条对角线合法必定中点重合 长度相同

暴力两辆计算竟然没T


#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long ll;

inline char nc()
{
	static char buf[100000],*p1=buf,*p2=buf;
	if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
	return *p1++;
}

inline void read(int &x){
	char c=nc(),b=1;
	for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
	for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

inline void read(ll &x){
	char c=nc(),b=1;
	for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
	for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

struct Point{
	ll x,y;
	Point(ll x=0,ll y=0):x(x),y(y) { }
	void read(){
		::read(x); ::read(y);
	}	
	friend bool operator < (const Point &A,const Point &B) {
		return A.x==B.x?A.y<B.y:A.x<B.x;
	}
	friend bool operator == (const Point &A,const Point &B) {
		return A.x==B.x && A.y==B.y;
	}
	friend Point operator + (const Point A,const Point B) {
		return Point(A.x+B.x,A.y+B.y);
	}
	friend Point operator - (const Point A,const Point B) {
		return Point(A.x-B.x,A.y-B.y);
	}
	friend ll operator * (const Point A,const Point B) {
		return A.x*B.y-B.x*A.y;
	}
	friend ll Dist(Point A,Point B){
		return (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y);
	}
	friend ll Cross(Point p1,Point p2,Point p0){
		return (p1-p0)*(p2-p0);
//		return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
	}
}P[1505];

struct Line{
	Point M;
	ll Len;
	int x,y;
	Line(){
	}
	Line(int ix,int iy){
		x=ix; y=iy;
		M=P[x]+P[y];
		Len=Dist(P[x],P[y]);
	}
	bool operator < (const Line &B) const{
		return Len==B.Len?M<B.M:Len<B.Len;
	}
}L[2250005];

int n,cnt;
ll ans;

inline ll Area(int a,int b){
	return abs(Cross(P[L[a].x],P[L[b].y],P[L[b].x]));
}

int main()
{
	freopen("t.in","r",stdin);
	freopen("t.out","w",stdout);
	read(n);
	for (int i=1;i<=n;i++)
		P[i].read();
	sort(P+1,P+n+1);
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
			L[++cnt]=Line(i,j);
	sort(L+1,L+cnt+1);
	for (int i=1;i<=cnt;i++)
		for (int j=i+1;j<=cnt && L[i].M==L[j].M && L[i].Len==L[j].Len;j++)
			ans=max(ans,Area(i,j));
	printf("%lld\n",ans);
	return 0;
}


你可能感兴趣的:([暴力 乱搞] BZOJ 2338 [HNOI2011]数矩形)