码迷,mamicode.com
首页 > 其他好文 > 详细

RotatingCaliper(WA)

时间:2017-10-09 22:38:19      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:double   ble   max   ret   ==   ota   def   struct   return   

#include <bits/stdc++.h>
#define p(a,b) (Point){a,b}
#define ALL(vec) vec.begin(),vec.end()
#define pow(a) ((a)*(a))
using namespace std;
struct Point{
    int x,y;
    double to(Point p){
    	return sqrt(pow(p.x+this->x)+pow(p.y+this->y));
	}
	double to(int x,int y){
    	return sqrt(pow(x+this->x)+pow(y+this->y));
	}
};
struct Vector{
    int x,y;
};
int operator *(Vector a,Vector b){
    return a.x*b.y+b.x*a.y;
}
int operator %(Vector a,Vector b){
    return a.x*b.y-b.x*a.y;
}
Vector operator -(Point a,Point b){
    return (Vector){a.x-b.x,b.x-b.y};
}
bool p_cmp(Point a,Point b){
    return a.x==b.x?a.y<b.y:a.x<b.x;
}
double slope(Point a,Point b){
    return (a.y-b.y)/(a.x-b.x);
}
typedef vector<Point> Point_Set;
void Graham(Point_Set &ps,Point_Set &ans){
Point s[10000];
int top=0;
    ans.clear();
    sort(ALL(ps),p_cmp);
    s[top++]=ps[0];
    s[top++]=ps[1];
    for(int i=2;i<ps.size();i++){
        while(top>1&&(ps[i]-s[top])*(s[top]-s[top-1])<0)top--;
        s[++top]=ps[i];
    }
    for(int i=0;i<=top;i++)
        ans.push_back(s[i]);
}
double RotatingCaliper(Point_Set &ps){
double ans=0,t1=-1,t2=0;
int i=0,j=1;
//	sort(ALL(ps),p_cmp);
	while(j<ps.size()){
		while(t1<t2){
			t1=t2;
			t2=ps[i].to(ps[j++]);
		}
		ans=max(ans,t1);
		i++;
	}
	return ans;
} 
int main(){
int n;
Point_Set ps,ans;
    cin>>n;
    for(int i=1;i<=n;i++){
        int a,b;
        cin>>a>>b;
        ps.push_back(p(a,b));
    }
    Graham(ps,ans);
    cout<<RotatingCaliper(ans);
    return 0;
}

  

RotatingCaliper(WA)

标签:double   ble   max   ret   ==   ota   def   struct   return   

原文地址:http://www.cnblogs.com/HC-LittleJian/p/7643073.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!