poj 2187 Beauty Contest
来源:互联网 发布:算法导论实现 编辑:程序博客网 时间:2024/06/06 19:17
凸包旋转卡壳
#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <cmath>#include <queue>#include <vector>using namespace std;#define N 50010#define epx 1e-8inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();} return x*f;}int n,m,top;double Ans;struct Point{ double x,y; Point operator - (const Point &a) const{ Point tmp; tmp.x=x-a.x,tmp.y=y-a.y; return tmp; } double operator * (const Point &a) const{ return x*a.y-y*a.x; }}p[N],S[N];double Dis(Point a,Point b){ return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}bool Cmp(const Point &a,const Point &b){ if(fabs((b-p[1])*(a-p[1]))<epx) return Dis(a,p[1])<Dis(b,p[1]); else return (a-p[1])*(b-p[1])>0;}void Graham(){ int t=1; for(int i=2;i<=n;i++) if(p[i].y<p[t].y||(p[i].y==p[t].y&&p[i].x<p[t].x)) t=i; swap(p[1],p[t]); sort(p+2,p+n+1,Cmp); S[++top]=p[1];S[++top]=p[2]; for(int i=3;i<=n;i++) { while((S[top]-S[top-1])*(p[i]-S[top-1])<=epx&&top>1) top--; S[++top]=p[i]; }}void RC(){ S[top+1]=p[1]; int now=2; for(int i=1;i<=top;i++) { while((S[i+1]-S[i])*(S[now]-S[i])<(S[i+1]-S[i])*(S[now+1]-S[i])) { now++; if(now==top+1)now=1; } Ans=max(Ans,max(Dis(S[now],S[i+1]),Dis(S[now],S[i]))); }}int main(){ n=read(); for(int i=1;i<=n;i++) p[i].x=read(),p[i].y=read(); Graham();RC(); printf("%lld\n",(long long)Ans); return 0;}
0 0
- POJ 2187 Beauty Contest
- poj 2187 Beauty Contest
- POJ 2187 Beauty Contest
- poj 2187 Beauty Contest
- POJ 2187 Beauty Contest
- POJ 2187 Beauty Contest
- poj 2187 Beauty Contest
- POJ 2187 Beauty Contest
- poj 2187 Beauty Contest
- Poj 2187 Beauty Contest
- poj 2187 Beauty Contest
- POJ 2187 Beauty Contest
- POJ 2187 Beauty Contest
- POJ 2187 Beauty Contest
- POJ 2187 Beauty Contest
- POJ 2187--Beauty Contest
- poj 2187 Beauty Contest
- poj 2187 Beauty Contest
- Java 进阶——单例模式
- UE32 删除空行正则表达式 .
- Print Numbers by Recursion
- c getchar() 函数的使用注意 、换行符的处理
- 关于git的命令行使用,新手学习笔记(新手入门级)
- poj 2187 Beauty Contest
- 全局队列/主队列/
- 机器学习和统计模型的差异
- poj 3320 Jessica's Reading Problem
- Qualcomm Atheros Device [168c:0041] (rev 20) ubuntu wifi driver
- App架构设计:接口设计
- Listview焦点问题
- 2015年第六届蓝桥杯C/C++程序设计本科B组省赛 九数组分数(代码填空)
- hdu5611 Baby Ming and phone number