您的位置:首页 > 其它

bzoj 2829 信用卡凸包(凸包)

2016-02-05 19:21 246 查看

2829: 信用卡凸包

Time Limit: 10 Sec Memory Limit: 128 MB

Submit: 1342 Solved: 577

[Submit][Status][Discuss]

Description

#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define FOR(a,b,c) for(int a=(b);a<=(c);a++)
using namespace std;

const int N = 400000+10;
const double PI = acos(-1.0);
const double eps = 1e-12;

int dcmp(double x) {
if(fabs(x)<eps) return 0; else return x<0? -1:1;
}

struct Pt {
double x,y;
Pt(double x=0,double y=0) :x(x),y(y) {};
};
typedef Pt vec;

vec operator - (Pt a,Pt b) { return vec(a.x-b.x,a.y-b.y); }
vec operator + (vec a,vec b) { return vec(a.x+b.x,a.y+b.y); }
bool operator == (Pt a,Pt b) {
return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0;
}
bool operator < (const Pt& a,const Pt& b) {
return a.x<b.x || (a.x==b.x && a.y<b.y);
}

vec rotate(vec a,double x) {
return vec(a.x*cos(x)-a.y*sin(x),a.x*sin(x)+a.y*cos(x));
}
double cross(vec a,vec b) { return a.x*b.y-a.y*b.x; }
double dist(Pt a,Pt b) {
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

vector<Pt> ConvexHull(vector<Pt> p) {
sort(p.begin(),p.end());
p.erase(unique(p.begin(),p.end()),p.end());
int n=p.size() , m=0;
vector<Pt> ch(n+1);
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--;
ch.resize(m); return ch;
}

int n;
double a,b,r;
vector <Pt> p,ch;

int main() {
scanf("%d%lf%lf%lf",&n,&b,&a,&r);
a-=2*r , b-=2*r; a/=2 , b/=2;
double x,y,ang,ans=0;
FOR(i,1,n) {
scanf("%lf%lf%lf",&x,&y,&ang);
Pt o=Pt(x,y);
p.push_back(o+rotate(vec(-a,-b),ang));
p.push_back(o+rotate(vec(-a,b),ang));
p.push_back(o+rotate(vec(a,-b),ang));
p.push_back(o+rotate(vec(a,b),ang));
}
ch=ConvexHull(p);
n=ch.size();
FOR(i,0,n-2)
ans+=dist(ch[i],ch[i+1]);
ans+=dist(ch[n-1],ch[0]);
ans+=2*PI*r;
printf("%.2lf",ans);
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: