uva 10652 Board Wrapping 凸包
来源:互联网 发布:重庆行知小小学校招聘 编辑:程序博客网 时间:2024/06/11 23:14
题意:
给出一些矩形,(长、宽、中心位置、顺时针旋转的角度),用一个最小的凸多边形把它围起来,求矩形面积和/凸多边形面积。
解法:求凸包
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>#include<vector>using namespace std;#define all(x) (x).begin(), (x).end()#define for0(a, n) for (int (a) = 0; (a) < (n); (a)++)#define for1(a, n) for (int (a) = 1; (a) <= (n); (a)++)#define mes(a,x,s) memset(a,x,(s)*sizeof a[0])#define mem(a,x) memset(a,x,sizeof a)typedef long long ll;typedef pair<int, int> pii;const int INF =0x3f3f3f3f;const double PI=cos(-1.0);struct 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,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); }Vector operator -(Vector A) {return Vector(-A.x,-A.y);}double torad(double deg){ return deg/180*acos(-1);}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.x-b.x)==0 &&dcmp(a.y-b.y)<0;}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)//向量A 逆时针旋转rad度{ return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad) );}Vector Normal(Vector A)//计算A的单位向量{ double L=Length(A); return Vector( -A.y/L,A.x/L );}int np;Point p[2500],ch[2500];int ConvexHell(Point *p,int n,Point *ch){ sort(p,p+n); int m=0; for(int i=0;i<n;i++) { while(m>1&&dcmp(Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2] )) <=0 ) m--;//叉乘<=0,逆时针,上凸 ch[m++]=p[i]; } int k=m; for(int i=n-2;i>=0;i--) { while(m>k &&dcmp( 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(){ std::ios::sync_with_stdio(false); int n,T;cin>>T; while(T--) { cin>>n; double x,y,w,h,ang,area1=0; np=0; for0(i,n) { cin>>x>>y>>w>>h>>ang; Point o(x,y); ang=-torad(ang); p[np++]=o+Rotate(Vector(-w/2,-h/2),ang); p[np++]=o+Rotate(Vector(w/2,-h/2),ang); p[np++]=o+Rotate(Vector(-w/2,h/2),ang); p[np++]=o+Rotate(Vector(w/2,h/2),ang); area1+=w*h; } int m=ConvexHell(p,np,ch); double area2=PolygonArea(ch, m);// cout<<area1<<" "<<area2<<endl; printf("%.1f %%\n",area1*100/area2); } 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 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(Graham凸包算法)
- UVA 10652 - Board Wrapping(二维凸包)
- UVA 10652 Board Wrapping(凸包+向量旋转)
- UVA 10652 Board Wrapping
- 循环链表
- XML的查询
- 多路IO复用 select 和 poll 函数简介
- andorid基础之预备讲义
- ZZULIOJ-1894-985的方格难题(动态规划)
- uva 10652 Board Wrapping 凸包
- activiti 流程走向异常 会签节点变量赋值为空问题
- 设置器与访问器。
- 131.Which naming method uses the tnsnames.ora file to store the connect descriptor used by the clien
- 替换空格
- 剖析并利用Visual Studio Code在Mac上编译、调试c#程序 集成到Unity3D
- 第五章 神经网络
- (NYoj 163)Phone List -- 字典树(水题)
- ZZULIOJ-1896-985的买饮料难题(水题)