BZOJ 2338: [HNOI2011]数矩形
2016-04-06 15:35
423 查看
先处理出一共O(n^2)条线段
然后找出长度相等,中点重合的线段,更新答案即可
事实上这么做极端情况下会被卡成n^3的复杂度,不过数据没有特殊构造还是能过的(其实是我也不会其他方法了)
然后找出长度相等,中点重合的线段,更新答案即可
事实上这么做极端情况下会被卡成n^3的复杂度,不过数据没有特殊构造还是能过的(其实是我也不会其他方法了)
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; const int N=1500+5; ll sqr(ll x){return x*x;} struct point{ ll x,y; bool operator < (const point &rhs)const{ if(x==rhs.x)return y<rhs.y; return x<rhs.x; } bool operator == (const point &rhs)const{ return x==rhs.x&&y==rhs.y; } }; struct seg{ ll l;point p; int p1,p2; bool operator < (const seg &rhs)const{ if(l==rhs.l)return p<rhs.p; return l<rhs.l; } bool operator == (const seg &rhs)const{ return l==rhs.l&&p==rhs.p; } }; point operator + (point a,point b){ return (point){a.x+b.x,a.y+b.y}; } point operator - (point a,point b){ return (point){a.x-b.x,a.y-b.y}; } ll length(point a,point b){ return sqr(a.x-b.x)+sqr(a.y-b.y); } point p ; seg s[N*N/2]; #define iabs(x) (x>0?x:-x) ll cross(point a,point b){ return a.x*b.y-a.y*b.x; } ll cross(point a,point b,point c){ return cross(b-a,c-a); } ll area(point a,point b,point c){ return iabs(cross(a,b,c)); } int main(){ //freopen("a.in","r",stdin); int n;scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%lld%lld",&p[i].x,&p[i].y); int tot=0; for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) s[++tot]=(seg){length(p[i],p[j]),p[i]+p[j],i,j}; sort(s+1,s+1+tot); ll ans=0; for(int i=1;i<=tot;i++) for(int j=i-1;j>=1&&s[i]==s[j];j--) ans=max(ans,area(p[s[i].p1],p[s[i].p2],p[s[j].p1])); printf("%lld\n",ans); return 0; }
相关文章推荐
- ping测试
- Maven 中 Missing artifact...问题
- CSS里的颜色简写(3位字母和6位字母)
- μC/OS-II学习之:任务,信号量、邮箱、队列及其区别
- python 用list,dic实现switch功能的一个奇葩现象
- 【蓝桥杯】历届试题 地宫取宝
- <input type="image">图片按钮具有提交功能
- expect简单用法
- linux oracle 系统安装oracle 11g所需的安装包和相关依赖包,无软件
- glusterfs 的存储卷类型
- glusterfs 的存储卷类型
- ViewPager预加载机制
- 判断回文链表
- JAVA WEB 总结 Servlet篇--源自技术
- leetcode——14——Longest Common Prefix最长公共前缀
- Qt调用webserver完成登录操作
- applePay 之 第一步merchantID和证书的生成
- 开发工具控制台使用方法总汇
- SQLSERVER2008 18456错误
- 每日所得