[bzoj1356]Rectangle[Baltic2009][几何常识乱搞]

虽然说是几何常识乱搞,但是想不到啊。。

题意:n个点取4个组成矩形,使面积最大,求面积。 n<=1500

题解:

  1.对角线相等且相互交于中点的四边形是矩形。

  2.矩形四点共圆。

  所以$n^2$枚举边,把线段中点和长度打包pair

  如果两条线的pair相等则可以构成一个圆,把相等的线段平方级枚举即可。

  考虑一个圆上的整点不多,常数小,所以没有T。。注意精度问题。

  【学习】http://blog.csdn.net/wzq_qwq/article/details/49005387

  感觉自己代码自带大常数。。有看出原因的,望留言指正谢谢:)

  

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 struct node
 6 {
 7     pair<int,int>    pr; long long len; int    x,y;
 8     bool    operator<(const node & temp)const
 9     {
10         if(pr!=temp.pr)return pr<temp.pr;
11         return len<temp.len;
12     }
13     bool    operator>(const node & temp)const
14     { return temp<*this; }
15     bool    operator==(const node & temp)const
16     { return !(*this<temp) && !(temp<*this); }
17 }vec[1501*1501];
18 
19 pair<int,int>    p[1600];
20 
21 double Dis(const int x,const int y)
22 {
23     return sqrt(1.0*(p[x].first-p[y].first)*(p[x].first-p[y].first)+
24         1.0*(p[x].second-p[y].second)*(p[x].second-p[y].second));
25 }
26 
27 int main()
28 {
29     int    n,tot=0;
30     scanf("%d",&n);
31     for(int i=1;i<=n;++i)
32         scanf("%d%d",&p[i].first,&p[i].second),
33             p[i].first<<=1,p[i].second<<=1;
34     for(int i=1;i<=n;++i) for(int j=1;j<=n;++j)
35       vec[++tot]=(node)
36     {
37       make_pair((p[i].first+p[j].first)>>1,(p[i].second+p[j].second)>>1),
38       1LL*(p[i].first-p[j].first)*(p[i].first-p[j].first)+
39         1LL*(p[i].second-p[j].second)*(p[i].second-p[j].second), i,j
40     };
41 
42     sort(vec+1,vec+tot+1);
43 
44     long long Ans=0;
45     for(int i=2;i<=tot;++i)
46     {
47         int l=i,r; while(vec[i]==vec[i-1])i++; r=i-1;
48         for(int j=l;j<=r;++j) for(int k=l;k<j;++k)
49         {
50             long long temp=(long long)(Dis(vec[j].x,vec[k].x)*
51                 Dis(vec[j].x,vec[k].y)+0.5);
52             if(temp>Ans)Ans=temp;
53         }
54     }
55 
56     printf("%lld
",Ans/4);
57     return 0;
58 }
原文地址:https://www.cnblogs.com/Gster/p/5604646.html