POJ - 2187(求凸包直径)
#include #include #include #include #include #include #include #include #include #define FRER() freopen("in.txt","r",stdin); #define FREW() freopen("out.txt","w",stdout); #define mem(a,b) memset(a,b,sizeof(a)); #define go int T;scanf("%d",&T);for(int cas=1;cas<=T;cas++) #define mod 1000000007 using namespace std; typedef pair pii; typedef long long ll; const int maxn = 500000 + 7; struct Point { int x,y; Point(int x=0,int y=0):x(x),y(y){} bool operator < (const Point& rhs) const { return x == rhs.x ? y < rhs.y : x < rhs.x; } }p[maxn],ch[maxn]; typedef Point Vector; Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);} Vector operator - (Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);} Vector operator * (Vector A,double p){return Vector(A.x*p,A.y*p); } Vector operator / (Vector A,double p){return Vector(A.x/p,A.y/p); } int Cross(Vector A,Vector B) {return A.x * B.y - A.y * B.x; } int dis(Point A,Point B) {return (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y);} int CH(int n){ sort(p,p+n); int m = 0; for(int i=0;i1&&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 rotate_caliper(int m){ int MAX = 0; if(m==3){ MAX = max(dis(ch[0],ch[1]),dis(ch[0],ch[2])); MAX = max(MAX,dis(ch[2],ch[1])); return MAX; } int j = 2; for(int i=0;i
gym101635K(求凸包宽度)
#include #include #include #include #include #include #include #include #include #define FRER() freopen("in.txt","r",stdin); #define FREW() freopen("out.txt","w",stdout); #define mem(a,b) memset(a,b,sizeof(a)); #define go int T;scanf("%d",&T);for(int cas=1;cas<=T;cas++) #define mod 1000000007 using namespace std; typedef pair pii; typedef long long ll; const int maxn = 500000 + 7 ; const double inf = 2e9; struct Point { ll x,y; Point(int x=0,int y=0):x(x),y(y){} bool operator < (const Point& rhs) const { return x == rhs.x ? y < rhs.y : x < rhs.x; } }p[maxn],ch[maxn]; typedef Point Vector; Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);} Vector operator - (Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);} Vector operator * (Vector A,double p){return Vector(A.x*p,A.y*p); } Vector operator / (Vector A,double p){return Vector(A.x/p,A.y/p); } ll Cross(Vector A,Vector B) {return A.x * B.y - A.y * B.x; } int dis(Point A,Point B) {return (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y);} double Dot(Vector A) {return sqrt(A.x*A.x+A.y*A.y); } double disPointToLine(Point A,Point P1,Point P2){ return fabs(1.0*Cross(A-P1,P2-P1)/Dot(P1-P2)); } int CH(int n){ sort(p,p+n); int m = 0; for(int i=0;i1&&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; } double rotate_caliper(int m){ double MIN = inf; if(m==2) return 0; if(m==3){ MIN = min(disPointToLine(ch[0],ch[1],ch[2]),disPointToLine(ch[1],ch[0],ch[2])); MIN = min(MIN,disPointToLine(ch[2],ch[1],ch[0])); return MIN; } int j = 2; for(int i=0;i