标签:ios oca eterm input esc time and direct tween
Description
Input
Output
Sample Input
4 0 0 0 1 1 1 1 0
Sample Output
2
Hint
凸包加旋转卡壳模板题,注意三个细节:凸包判断时注意变量i和tot,卡壳时注意一个next(j)!=i的条件,然后和只有两个点时的特判;
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cctype> #include<cstring> #include<string> #include<ctime> #include<algorithm> using namespace std; struct point { int x; int y; }p[50005],q[50005]; inline int operator*(point a,point b) { return a.x*b.y-a.y*b.x; } inline point operator-(point a,point b) { point t; t.x=a.x-b.x; t.y=a.y-b.y; return t; } inline int norm(point a) { return a.x*a.x+a.y*a.y; } bool comp(int u,int v) { int det=(p[u]-p[1])*(p[v]-p[1]); if(det!=0) return det>0; return norm(p[u]-p[1])<norm(p[v]-p[1]); } int n,m; int next(int i) { if(i!=m) return ++i; else return 1; } void tubao() { int id=1; for(int i=2;i<=n;i++) if(p[id].x>p[i].x||(p[id].x==p[i].x&&p[id].y>p[i].y)) id=i; if(id!=1) swap(p[id],p[1]); int per[50005]; for(int i=1;i<=n;i++) per[i]=i; sort(per+2,per+n+1,comp); q[++m]=p[1]; for(int i=2;i<=n;i++) { int j=per[i]; while(m>=2&&(q[m]-q[m-1])*(p[j]-q[m-1])<=0) m--; q[++m]=p[j]; } q[++m]=p[1]; } int area(point u,point v,point s) { return (u-s)*(v-s); } int solve() { if(m==2) return (norm(q[1]-q[2])); q[m+1]=q[1]; int res=0; for(int i=1,j=3;i<=m;i++) { while(next(j)!=i&&area(q[i],q[i+1],q[j+1])>=area(q[i],q[i+1],q[j])) j=next(j); res=max(res,norm(q[i+1]-q[j])); res=max(res,norm(q[i]-q[j])); } return res; } int main() { //freopen("a.in","r",stdin); scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y); tubao(); int ans=solve(); cout<<ans<<endl; }
标签:ios oca eterm input esc time and direct tween
原文地址:http://www.cnblogs.com/AseanA/p/6662407.html