UVALive 4728 Squares(旋转卡壳)
2014-12-08 11:43
579 查看
Squares
The famous Korean IT company#include <bits/stdc++.h> using namespace std; const int N = 100005 ; int n , tot ; struct Point { int x , y ; Point(){}; Point(int a , int b ){x=a,y=b;} bool operator < ( const Point &a ) const { if( x != a.x )return x < a.x ; else return y < a.y ; } }p[N<<2],ch[N<<2]; inline int Cross( Point a , Point b ) { return a.x*b.y-a.y*b.x ; } inline int dis( Point a , Point b ) { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);} Point operator - ( Point a , Point b ) { return Point(a.x-b.x,a.y-b.y); } int ConvexHull( Point* p , int n , Point* ch ){ int m = 0 ; sort( p , p + n ); for( int i = 0 ; i < n ; ++i ) { while( m > 1 && Cross( ch[m-1]-ch[m-2] , p[i]-ch[m-2] ) <= 0 ) m--; ch[m++] = p[i]; } int k = m ; for( int i = n-2 ; i >=0 ; --i ){ while( m > k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2]) <= 0 ) m--; ch[m++] = p[i]; } if( n > 1 ) m--; return m ; } int Rotating_Calipers( Point* poly , int n ) { int j = 1 , ans = 0 ; poly = poly[0] ; for( int i = 0 ; i < n ; ++i ) { while( fabs( Cross(poly[i+1]-poly[i],poly[j]-poly[i]) ) < fabs( Cross(poly[i+1]-poly[i],poly[j+1]-poly[i]))) j=(j+1)%n ; ans = max( ans , max( dis(poly[i],poly[j]) , dis(poly[i+1] ,poly[j]))); } return ans ; } void Run() { int x , y , w ; scanf("%d",&n); tot = 0 ; for( int i = 0 ; i < n ; ++i ) { scanf("%d%d%d",&x,&y,&w); p[tot++]=Point(x,y); p[tot++]=Point(x+w,y); p[tot++]=Point(x+w,y+w); p[tot++]=Point(x,y+w); } int m = ConvexHull( p , tot , ch ); printf("%d\n",Rotating_Calipers(ch,m)); } int main(){ int _ ; scanf("%d",&_); while(_--) Run(); }
View Code
相关文章推荐
- UVALive 4728 Squares(旋转卡壳求凸包直径)
- Uvalive 4728 Squares(旋转卡壳)
- UVALive 4728 (凸包 旋转卡壳)
- 凸包扫描 + 旋转卡壳 UVALive 4728
- UVA 4728 Squares(凸包+旋转卡壳)
- uvalive 4728(旋转卡壳求凸包最长直径)
- LA 4728 (旋转卡壳) Squares
- uva 1453 - Squares(旋转卡壳)
- LA 4728 Squares 旋转卡壳
- UVALive 4728 Squares (平面最远点对)
- LA 4728 Squares (二维凸包+旋转卡壳)
- UVALive 4728 Squares
- Squares UVALive - 4728
- uva 1453 Squares (旋转卡壳 rotating calipers)
- UVa 1453 - Squares 旋转卡壳求凸包直径
- UVA 12307 Smallest Enclosing Rectangle(旋转卡壳)
- UVA 10173 最小矩形覆盖(凸包+旋转卡壳)
- 【LA 4728】Square, Seoul 2009 (凸包,旋转卡壳)
- UVa1453或La4728 凸包+枚举(或旋转卡壳)
- UVA 10173 最小矩形覆盖(凸包+旋转卡壳)