bzoj 2829 信用卡凸包(凸包)
2016-02-05 19:21
246 查看
2829: 信用卡凸包
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 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
相关文章推荐
- 【Stanford CNN课程笔记】3. 梯度下降法
- c和指针程序6.2与6.3 分析
- POJ 1456:Supermarket【贪心】
- 树和二叉树
- poj 3159 Candies(差分约束系统)
- [Redux] Passing the Store Down Explicitly via Props
- ubuntu14操作系统chrome标签和书签乱码解决
- Java [Leetcode 190]Reverse Bits
- 与一线Linux嵌入式开发project师的对话
- poj 3620 Avoid The Lakes
- junit测试延伸--方法的重复测试
- junit测试延伸--方法的重复测试
- MySQL多实例管理
- zoj1093 dp入门
- 常用meta整理,页面技术,SEO优化
- 异或(Exclusive-OR,Wuhan 2009,LA 4487)
- 【HDU 2160】母猪的故事
- 在开发板(JZ2440)里启动内核出现了--Bad Data CRC
- C语言:链表实现的一个实例
- C语言:链表实现的一个实例