UVA 10652 - Board Wrapping(求凸包)
来源:互联网 发布:魔兽世界wlk首杀数据 编辑:程序博客网 时间:2024/05/29 07:13
这个题是 是给出好多个矩形,求外围的凸多边形的最小面积。
给出矩形的中心和旋转角度之后 先求出所有的点 然后求凸包就OK了。
求出凸包所有的点。然后求凸多边形就解决了。
#include <cstdio>#include <algorithm>#include <iostream>#include <cstring>#include <cmath>#include <cstdlib>#include <string>#include <map>#include <vector>#include <set>#include <queue>#include <stack>#include <cctype>using namespace std;#define ll long longtypedef unsigned long long ull;#define maxn 10010#define INF 1<<30struct Point{ double x,y; Point(double x = 0, double y = 0):x(x),y(y) {}};typedef Point Vector ;Vector operator + (Vector A, Vector B){ return Vector(A.x + B.x, A.y + B.y);}Vector operator - (Vector A, Point 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);}bool operator < (const Point & a, const Point & b){ return a.x < b.x || (a.x == b.x && a.y < b.y);}const double eps = 1e-10;int dcmp(double x){ if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;}bool operator == (const Point & a, const Point & b){ return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;}double Dot(Vector A, Vector B){ return A.x * B.x + A.y * B.y;} // 点积double Length(Vector A) { return sqrt(Dot(A, A));} //向量长度double Angle(Vector A, Vector B){ return acos(Dot(A, B)/Length(A)/Length(B));} //夹角double Cross(Vector A, Vector B){return A.x*B.y - A.y * B.x;} //叉积(面积两倍)double Area2(Point A, Point B, Point C){return Cross(B-A,C-A);} // 面积两倍Vector Rotate(Vector A, double rad){return Vector(A.x*cos(rad) - A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));}// 旋转后的直线</span>Vector Normal(Vector A){ double L = Length(A); return Vector(-A.y/L, A.x/L);}Point GetLineIntersection(Point P, Point v, Point Q, Point w){ //求直线 pv 与qw的交点 Vector u = P-Q; double t = Cross(w, u) / Cross(v, w); return P+v*t;}double DistanceToline(Point P, Point A, Point B){ //点到直线的距离 Vector v1 = B - A,v2 = P - A; return fabs(Cross(v1,v2))/Length(v1);}double DistanceTpsegment(Point P, Point A, Point B){ //点到线段的距离 if(A == B) return Length(P-A); Vector v1 = B - A, v2 = P - A, v3 = P - B; if(dcmp(Dot(v1, v2)) < 0) return Length(v2); else if(dcmp(Dot(v1,v3)) > 0) return Length(v3); else return fabs(Cross(v1, v2)) / Length(v1);}Point GetLinePrijection(Point P, Point A, Point B){ // 点在直线上的投影 Vector v = B-A; return A+v*(Dot(v, P-A)/Dot(v,v));}bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2){ // 线段相交判定(不包括在端点处的情况) double c1 = Cross(a2 - a1,b1-a1) ,c2 = Cross(a2 - a1,b2-a1), c3 = Cross(b2 - b1, a1-b1), c4 = Cross(b2 - b1, a2 - b1); return dcmp(c1)*dcmp(c2) < 0 && dcmp(c3)*dcmp(c4) < 0;}bool OnSegment(Point p, Point a1, Point a2){ //线段在端点处是否可能相交 return dcmp(Cross(a1-p, a2-p)) == 0 && dcmp(Dot(a1-p, a2-p)) < 0;}double ConvexPolygonArea(Point * p,int n){ // 多边形的有向面积 double area = 0; for(int i = 1; i < n-1; i++) area += Cross(p[i] - p[0],p[i+1] - p[0]); return area/2;}int ConvexHull(Point *p, int n, Point * ch){ sort(p, p+n); int m = 0; 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;}double PolygonArea(Point * p, int n){ double area = 0; for(int i = 1; i < n-1; i++) area += Cross(p[i] - p[0], p[i+1]-p[0]); return area/2;}int main (){ int kase; scanf("%d",&kase); while(kase--){ int n; scanf("%d",&n); Point po[maxn]; Point af[maxn]; int num = 0; double sum_ar = 0; for(int i = 0; i < n; i++){ double x,y,w,h,j; scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&j); Point o(x,y); j = -j/180*acos(-1); po[num++] = o + Rotate(Vector(-w/2, -h/2),j); po[num++] = o + Rotate(Vector(-w/2, h/2),j); po[num++] = o + Rotate(Vector(w/2, -h/2),j); po[num++] = o + Rotate(Vector(w/2, h/2),j); sum_ar += w*h; } int x = ConvexHull(po, num, af); double area_sum = PolygonArea(af, x); double bi = sum_ar/area_sum*100; printf("%.1lf %%\n",bi); } return 0;}
0 0
- UVA 10652 - Board Wrapping(求凸包)
- UVA 10652 Board Wrapping
- UVA 10652 Board Wrapping
- uva 10652 Board Wrapping
- UVA 10652 Board Wrapping
- Uva - 10652 - Board Wrapping
- uva 10652Board Wrapping
- UVa 10652 Board Wrapping
- UVA 10652 Board Wrapping .
- UVA 10652 Board Wrapping
- uva 10652 - Board Wrapping(凸包)
- Uva 10652 Board Wrapping(凸包)
- UVA 10652 Board Wrapping(计算几何基础,求凸包)
- uva 10652 Board Wrapping (计算几何-凸包)
- 【UVA】10652-Board Wrapping(凸包问题)
- UVA 10652 - Board Wrapping(二维凸包)
- UVA 10652 Board Wrapping 凸包模板
- UVa 10652 Board Wrapping 凸包
- UniFi无缝漫游讲解-EDCWIFI吴伟明
- STL 学习
- 自定义TRACE函数,用于向Output Window、控制台和文件输出Log
- CocoaPods安装和使用教程
- java 笔试题-> swing 布局管理器有哪几种
- UVA 10652 - Board Wrapping(求凸包)
- Android实现本地推送通知的解决方案
- root荣耀3C之后修改hosts的方法
- 由链表初始化看C语言的二级指针
- iPhone之AVAudioPlayer
- python 列表推导式 - 轻量级循环
- Perl安装和使用DBI
- Oracle分组函数之ROLLUP魅力
- inputAccessoryView,inputView