uva 10652 Board Wrapping (计算几何-凸包)

Problem B

Board Wrapping

Input: standard input

Output: standard output

Time Limit: 2 seconds

The small sawmill in Mission, British Columbia, has developed a brand new way of packaging boards for drying. By fixating the boards in special moulds, the board can dry efficiently in a drying room.

Space is an issue though. The boards cannot be too close, because then the drying will be too slow. On the other hand, one wants to use the drying room efficiently.

Looking at it from a 2-D perspective, your task is to calculate the fraction between the space occupied by the boards to the total space occupied by the mould. Now, the mould is surrounded by an aluminium frame of negligible thickness, following
the hull of the boards‘ corners tightly. The space occupied by the mould would thus be the interior of the frame.

Input

On the first line of input there is one integer, N <= 50, giving the number of test cases (moulds) in the input. After this line, N test cases follow. Each test case starts with a line containing one integer n1<
n <= 600
, which is the number of boards in the mould. Then n lines follow, each with five floating point numbers x, y, w, h, j where 0 <= x, y, w, h <=10000 and –90° < j <=90°. The x and y are
the coordinates of the center of the board and w and h are the width and height of the board, respectively. j is the angle between the height axis of the board to the y-axis in degrees, positive
clockwise. That is, if j = 0, the projection of the board on the x-axis would be w. Of course, the boards cannot intersect.

Output

For every test case, output one line containing the fraction of the space occupied by the boards to the total space in percent. Your output should have one decimal digit and be followed by a space and a percent sign (%).

Sample Input                              Output for Sample Input


1

4

4 7.5 6 3 0

8 11.5 6 3 0

9.5 6 6 3 90

4.5 3 4.4721 2.2361 26.565


64.3 %


Swedish National Contest

The Sample Input and Sample Output corresponds to the given picture

题目大意:

给n个矩形木板,你要用一个面积尽量小的凸多边形把它们包起来,求木板占整个包装面积的百分比。

解题思路:

最主要还是求凸包。

解题代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

const double eps=1e-7;
struct Point{
    double x,y;
    Point(double x0=0,double y0=0){
        x=x0,y=y0;
    }
    void read(){ scanf("%lf%lf",&x,&y); }
    friend bool operator < (Point a,Point b){
        if(a.y!=b.y) return a.y<b.y;
        else return a.x<b.x;
    }
    double getdis(Point q){ return sqrt( (x-q.x)*(x-q.x)+(y-q.y)*(y-q.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); }

int dcmp(double x) { if(fabs(x)<eps) return 0; else return x<0?-1:1; }
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; }
Vector Rotate(Vector A,double rad){ return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad)); }//逆时针旋转rad角度
double torad(double ang){ return ang/180.0*acos(-1.0); }

const int maxn=2500;
Point p[maxn];
int n,top;
double sum;

bool cmp(Point a,Point b){
    if( fabs( Cross(a-p[0],b-a) )<eps ) return a.getdis(p[0])<b.getdis(p[0]);
    else return Cross(a-p[0],b-a)>0;
}

double ConvexHull(){
    top=1;
    sort(p,p+n);
    sort(p+1,p+n,cmp);
    for(int i=2;i<n;i++){
        while(top>0 && Cross(p[top]-p[top-1],p[i]-p[top-1])<=0) top--;
        p[++top]=p[i];
    }
    p[++top]=p[0];
    double area=0;
    for(int i=1;i<top;i++){
        area+=Cross(p[i]-p[0],p[i+1]-p[0]);
    }
    return area/2.0;
}

void input(){
    n=0;
    sum=0;
    int m;
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        Point o;
        double w,h,ang,rad;
        scanf("%lf%lf%lf%lf%lf",&o.x,&o.y,&w,&h,&ang);
        rad=-torad(ang);
        p[n++]=o+Rotate(Vector(-w/2.0,-h/2.0),rad);
        p[n++]=o+Rotate(Vector(-w/2.0,h/2.0),rad);
        p[n++]=o+Rotate(Vector(w/2.0,h/2.0),rad);
        p[n++]=o+Rotate(Vector(w/2.0,-h/2.0),rad);
        sum+=w*h;
    }
}

void solve(){
    double ans=ConvexHull();
    printf("%.1lf %%\n",sum*100.0/ans);
}

int main(){
    int T;
    scanf("%d",&T);
    while(T-- >0){
        input();
        solve();
    }
    return 0;
}

uva 10652 Board Wrapping (计算几何-凸包)

时间: 2024-12-30 03:18:56

uva 10652 Board Wrapping (计算几何-凸包)的相关文章

UVA 10652 Board Wrapping 计算几何

多边形凸包.... Board Wrapping Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem B Board Wrapping Input: standard input Output: standard output Time Limit: 2 seconds The small sawmill in Mission, Britis

UVA 10652 Board Wrapping(凸包)

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32286 [思路] 凸包 根据角度与中心点求出长方形所有点来,然后就可以应用凸包算法了. [代码] #include<cmath> #include<cstdio> #include<algorithm> using namespace std; const double PI = acos(-1.0); double torad(doub

Uva 10652 Board Wrapping

二次联通门 : Virtual Judge Uva 10652 Board Wrapping /* Uva 10652 Board Wrapping 计算几何 将每个家具拆为4个点 对所有点求一个凸包 然后求凸包的面积即可 思路不难.. 但是写起来好麻烦好麻烦 需要注意的东西有很多 1. 角度制转弧度制 2. EPS的选择 3. PI的取值 (以防万一以后还是都写acos(-1)吧...) 4. 在把家具拆成四个点时的细节 4. 计算多边形的面积 */ #include <algorithm>

Uva - 10652 Board Wrapping(凸包)

给定一些长方形的坐标,求长方形的面积与围住这些长方形面积的凸包的百分比. 首先假设长方形都是水平放置,那么根据长和宽还有中心坐标,可以求出四个顶点的坐标,然后求出从中心指向顶点的向量,和角度转化成的弧度,向量旋转之后得到一个新的向量 是由中心指向新的顶点,加上中心点就得到新的顶点的坐标.可以画图理解. 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm&

UVA 10652 Board Wrapping(二维凸包)

传送门 刘汝佳<算法竞赛入门经典>P272例题6包装木板 题意:有n块矩形木板,你的任务是用一个面积尽量小的凸多边形把它们抱起来,并计算出木板占整个包装面积的百分比. 输入:t组数据,每组先输入木板个数n,接下来n行,每行x,y,w,h,j.(x,y)是木板中心的坐标,w是宽,h是高,j是顺时针旋转的角度. 木板互不相交. 输出:对于每组数据,输出木板总面积占包装总面积的百分比,保留小数点后1位. 题解:典型的二维凸包问题,理解并调用模板即可. #include <math.h>

简单几何(向量旋转+凸包+多边形面积) UVA 10652 Board Wrapping

题目传送门 题意:告诉若干个矩形的信息,问他们在凸多边形中所占的面积比例 分析:训练指南P272,矩形面积长*宽,只要计算出所有的点,用凸包后再求多边形面积.已知矩形的中心,向量在原点参考点再旋转,角度要转换成弧度制. /************************************************ * Author :Running_Time * Created Time :2015/11/10 星期二 10:34:43 * File Name :UVA_10652.cpp

UVA 10652 Board Wrapping(计算几何基础,求凸包)

题目链接:传送门 分析: 没有什么好说的就是求一个凸包就好了.可以当作模板. 代码如下: #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; const double eps = 1e-10; //判断符号,提高精度 int dcmp(double x){ if(fab

Board Wrapping(计算几何求凸包加向量的旋转)

UVA - 10652 Board Wrapping Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Submit]   [Go Back]   [Status] Description Problem B Board Wrapping Input: standard input Output: standard output Time Limit: 2 seconds The small sa

计算几何--凸包总结

计算几何凸包 凸包:给你n个散落的点,让你求出最小的凸多边形将所有的点包括起来,或者点在边上.用到的算法是Graham Graham算法:首先找到一个顶点作为基点,然后将这个点与其他点进行连线,然后按照角度的大小进行排序. 然后加点,第一个点肯定在凸多边形上,然后开始加点,每加一个点,要用向量的×积判断以前是不是有边在他的里面,如果有的话,就将这个点替换,这个过程是一个回溯的过程 首先找基点,纵坐标最小的一定在凸包上,如果纵坐标相等那么就选横坐标小的. 下面模拟一下Graham算法扫描的过程(截