学习旋转卡壳请戳这里~感觉讲的最好的就是这个了……
其实就是找面积最大的三角形?。。。并且满足单调……
嗯反正就是这样……
这是一道模板题
好像必须写成循环访问?我在原数组后面复制了一遍点,结果挂了……改成cur=cur%n+1就过了QAQ
//其实是不是数组没开够所以复制的方法就爆了?
UPD:(2015年5月13日 20:40:45)
其实是我点保存在1~n里面,所以复制的时候不能写p[i+n-1]=p[i]; 而应该是p[i+n]=p[i];……QAQ我是傻逼
1 Source Code 2 Problem: 2187 User: sdfzyhy 3 Memory: 1044K Time: 32MS 4 Language: G++ Result: Accepted 5 6 Source Code 7 8 //POJ 2187 9 #include<cstdio> 10 #include<cstring> 11 #include<cstdlib> 12 #include<iostream> 13 #include<algorithm> 14 #define rep(i,n) for(int i=0;i<n;++i) 15 #define F(i,j,n) for(int i=j;i<=n;++i) 16 #define D(i,j,n) for(int i=j;i>=n;--i) 17 #define pb push_back 18 using namespace std; 19 typedef long long LL; 20 inline int getint(){ 21 int r=1,v=0; char ch=getchar(); 22 for(;!isdigit(ch);ch=getchar()) if (ch=='-') r=-1; 23 for(; isdigit(ch);ch=getchar()) v=v*10-'0'+ch; 24 return r*v; 25 } 26 const int N=100010; 27 /*******************template********************/ 28 struct Poi{ 29 int x,y; 30 Poi(){} 31 Poi(int x,int y):x(x),y(y){} 32 void read(){x=getint();y=getint();} 33 }p[N],ch[N]; 34 typedef Poi Vec; 35 Vec operator - (const Poi &a,const Poi &b){return Vec(a.x-b.x,a.y-b.y);} 36 bool operator < (const Poi &a,const Poi &b){return a.x<b.x || (a.x==b.x && a.y<b.y);} 37 inline int Cross(const Poi &a,const Poi &b){return a.x*b.y-a.y*b.x;} 38 inline int Dot(const Poi &a,const Poi &b){return a.x*b.x+a.y*b.y;} 39 int n,m,ans; 40 41 void graham(Poi *p,int n){ 42 int size=0; 43 sort(p+1,p+n+1); 44 ch[++m]=p[1]; 45 F(i,2,n){ 46 while(m>1 && Cross(ch[m]-ch[m-1],p[i]-ch[m-1])<=0) m--; 47 ch[++m]=p[i]; 48 } 49 int k=m; 50 D(i,n-1,1){ 51 while(m>k && Cross(ch[m]-ch[m-1],p[i]-ch[m-1])<=0) m--; 52 ch[++m]=p[i]; 53 } 54 if (n>1) m--; 55 } 56 57 void rot(Poi *p,int n){ 58 ans=0; 59 // F(i,1,n-1) p[n+i-1]=p[i]; 60 // n=n*2-1; 61 int cur=2; 62 F(i,1,n){ 63 Vec v = p[i]-p[i+1]; 64 while(Cross(p[i+1]-p[i],p[cur+1]-p[i]) > Cross(p[i+1]-p[i],p[cur]-p[i])) 65 cur=(cur%n)+1; 66 ans=max(ans,Dot(p[cur]-p[i],p[cur]-p[i])); 67 ans=max(ans,Dot(p[cur+1]-p[i+1],p[cur+1]-p[i+1])); 68 } 69 } 70 71 int main(){ 72 #ifndef ONLINE_JUDGE 73 freopen("2187.in","r",stdin); 74 // freopen("2187.out","w",stdout); 75 #endif 76 n=getint(); 77 F(i,1,n) p[i].read(); 78 graham(p,n); 79 rot(ch,m); 80 printf("%d\n",ans); 81 return 0; 82 }