UVA - 10652 Board Wrapping (凸包+多边形面积)

原创 2018年04月15日 21:31:55
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const double ep=1e-10;
const int maxn=6e3+10;
int cnt;

struct Point {
	double x, y;
	Point(){}
	Point(double x, double y): x(x), y(y){}
	bool operator < (const Point A) const{ return x<A.x || (x==A.x&&y<A.y);}
	
}p[maxn], ch[maxn];
typedef Point Vector;

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

Point operator + (Point A, Vector B) { return Point(A.x+B.x, A.y+B.y); }
Point operator - (Point 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 (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 Cross(Vector A, Vector B){ return A.x*B.y-A.y*B.x; }

bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2){
	double c1=Cross(a2-a1, b1-a1), c2=Cross(a2-a1, b2-a1);
	double c3=Cross(b2-b1, a1-b1), c4=Cross(b2-b1, a2-b1);
	return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0;
}

Point GetLineIntersection(Point a1, Vector v1, Point a2, Vector v2){
	Vector v=a1-a2;
	double t=Cross(v2, v)/Cross(v1, v2);
	return a1+v1*t;
}

bool OnSegment(Point p, Point a, Point b){
	return dcmp(Cross(a-p, b-p))==0 && dcmp(Dot(a-p, b-p))<0;
}

Vector Rotate(Vector A, double rad){
	return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
}

void GetPoint(Point t, double w, double h, double rad){
	p[cnt++]=t + Rotate(Vector(w/2, h/2), rad);
	p[cnt++]=t + Rotate(Vector(-w/2, h/2), rad);
	p[cnt++]=t + Rotate(Vector(-w/2, -h/2), rad);
	p[cnt++]=t + Rotate(Vector(w/2, -h/2), rad);
}

int ConvexHull(){
	sort(p, p+cnt);
	
	int m=0;
	for(int i=0; i<cnt; 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=cnt-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(cnt>1) m--;
	
	return m;
}

double PolygonArea(int m){
	double area =0;
	for(int i=1; i<m-1; i++)
		area+=Cross(ch[i]-ch[0], ch[i+1]-ch[0]);
	return area/2;
}

double torad(double x){
	return x/180 * acos(-1);
}

int main() {
	int T;
	scanf("%d", &T);
	while(T--){
		int n;
		cnt=0;
		double s1=0, x, y, w, h, j, rad;
		scanf("%d", &n);
		for(int i=0; i<n; i++)
		{
			Point t;
			scanf("%lf%lf%lf%lf%lf", &t.x, &t.y, &w, &h, &j);
			rad=torad(j);
			GetPoint(t, w, h, -rad);
			s1+=w*h;
		}
		
		int m=ConvexHull();
		
		double s=PolygonArea(m);
		
		double percenty=s1/s*100;
		printf("%.1lf %\n", percenty);
	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/du_lun/article/details/79953600

UVA 10652 Board Wrapping

大意:有n块矩形木板,你的任务是用一个面积尽量小的凸多边形把它们包起来,并计算出木板站整个包装面积的百分比。 思路:按照题意将所有矩形顶点坐标存起来,旋转时先旋转从中心出发的向量,求得各个坐标之后,...
  • Wall_F
  • Wall_F
  • 2013-04-03 20:27:41
  • 867

UVa 10652 Board Wrapping 凸包

题目地址:pdf j
  • jingqi814
  • jingqi814
  • 2014-04-18 01:29:12
  • 304

【UVa 10652】Board Wrapping (凸包)

Description 给定很多块木板,用面积尽量小的多边形将其包起来。 Solution 将木板的四个点全部加入点集,求凸包即可。 Source /**************...
  • hhaannyyii
  • hhaannyyii
  • 2018-02-12 21:37:53
  • 36

Uva 10652 Board Wrapping(凸包)

题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem...
  • wang2147483647
  • wang2147483647
  • 2017-08-18 17:48:53
  • 228

uva 10652 Board Wrapping 凸包

题意: 给出一些矩形,(长、宽、中心位置、顺时针旋转的角度),用一个最小的凸多边形把它围起来,求矩形面积和/凸多边形面积。 解法:求凸包 #include #includ...
  • yskyskyer123
  • yskyskyer123
  • 2016-08-03 18:16:01
  • 270

UVA 10652 Board Wrapping 凸包

点击打开题目链接
  • Houheshuai
  • Houheshuai
  • 2016-05-11 21:49:19
  • 394

uva 10652 - Board Wrapping(凸包)

题目链接:uva 10652 - Board Wrapping 处理出所有顶点,求凸包的面积。 #include #include #include #include #i...
  • u011328934
  • u011328934
  • 2015-08-21 22:43:54
  • 345

uva 10652 Board Wrapping

uva 10652 Board Wrapping
  • tengfei461807914
  • tengfei461807914
  • 2016-07-31 22:49:46
  • 210

UVA 10652 Board Wrapping

哇咔咔,这题RANK 8 (*^__^*) 嘻嘻……巨开心~~  其实这题也不难哈,但是为嘛做的人这么少捏。。 就是给你N个矩形,问你所有矩形的面积占包围这个矩形的面积的百分比。 矩形的面积很好弄,长...
  • zxy_snow
  • zxy_snow
  • 2011-06-21 23:31:00
  • 827

Uva - 10652 - Board Wrapping

题意:给出n个矩形的中心坐标以及长宽和相对于y轴的旋转角度,问矩形总面积与最小外围总面积的百分比(N组测试数据 题目链接:http://uva.onlinejudge.org/index.php?...
  • SCNU_Jiechao
  • SCNU_Jiechao
  • 2013-09-21 09:41:33
  • 927
收藏助手
不良信息举报
您举报文章:UVA - 10652 Board Wrapping (凸包+多边形面积)
举报原因:
原因补充:

(最多只允许输入30个字)