题意

PDF

分析

就是一个裸的凸包。

如何确定点?就用中心向四边连垂直的向量然后旋转,加上中心点,即可得出旋转后的点。

时间复杂度\(O(T n \log n)\)

代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<ctime>
#include<cstring>
#define rg register
#define il inline
#define co const
template<class T>il T read()
{
    rg T data=0;
    rg int w=1;
    rg char ch=getchar();
    while(!isdigit(ch))
    {
        if(ch=='-')
            w=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        data=data*10+ch-'0';
        ch=getchar();
    }
    return data*w;
}
template<class T>T read(T&x)
{
    return x=read<T>();
}
using namespace std;
typedef long long ll;

co double eps=1e-10;

int dcmp(double x)
{
    return fabs(x)<=eps?0:(x<0?-1:1);
}

struct Point
{
    double x,y;

    Point(double x=0,double y=0)
    :x(x),y(y){}

    bool operator<(co Point&rhs)co
    {
        return dcmp(x-rhs.x)?x<rhs.x:y<rhs.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);
}

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;
}

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

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&&dcmp(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&&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 n,pc;
Point P[2500],ch[2500];

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

int main()
{
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    int T=read<int>();
    while(T--)
    {
        pc=0;
        double area1=0;
        read(n);
        for(int i=0;i<n;++i)
        {
            double x,y,w,h,ang;
            scanf("%lf %lf %lf %lf %lf",&x,&y,&w,&h,&ang);
            Point o(x,y);
            ang=-torad(ang);
            P[pc++]=o+Rotate(Vector(-w/2,-h/2),ang);
            P[pc++]=o+Rotate(Vector(w/2,-h/2),ang);
            P[pc++]=o+Rotate(Vector(-w/2,h/2),ang);
            P[pc++]=o+Rotate(Vector(w/2,h/2),ang);
            area1+=w*h;
        }
        int m=ConvexHull(P,pc,ch);
        double area2=PolygonArea(ch,m);
        printf("%.1lf %%\n",area1*100/area2);
    }
    return 0;
}

UVA10652 Board Wrapping的更多相关文章

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

    Problem B Board Wrapping Input: standard input Output: standard output Time Limit: 2 seconds The sma ...

  2. UVA 10652 Board Wrapping 计算几何

    多边形凸包.. .. Board Wrapping Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu ...

  3. 【UVA10652】Board Wrapping(求凸包面积)

    点此看题面 大致题意: 告诉你若干个矩形的重心坐标.长.宽和相对\(y\)轴的偏转角度,求矩形面积和与能围住这些矩形的最小凸包面积之比. 矩形面积和 这应该是比较好求的吧. 已经给了你长和宽,直接乘起 ...

  4. UVA 10652 Board Wrapping(凸包)

    The small sawmill in Mission, British Columbia, hasdeveloped a brand new way of packaging boards for ...

  5. ●UVA 10652 Board Wrapping

    题链: https://vjudge.net/problem/UVA-10652 题解: 计算几何,Andrew求凸包, 裸题...(数组开小了,还整了半天...) 代码: #include<c ...

  6. uva 10625 Board Wrapping

    https://vjudge.net/problem/UVA-10652 给出n个长方形,用一个面积尽量小的凸多边形把他们围起来 求木板占包装面积的百分比 输入给出长方形的中心坐标,长,宽,以及长方形 ...

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

    题目传送门 题意:告诉若干个矩形的信息,问他们在凸多边形中所占的面积比例 分析:训练指南P272,矩形面积长*宽,只要计算出所有的点,用凸包后再求多边形面积.已知矩形的中心,向量在原点参考点再旋转,角 ...

  8. UVa 10652 (简单凸包) Board Wrapping

    题意: 有n块互不重叠的矩形木板,用尽量小的凸多边形将它们包起来,并输出并输出木板总面积占凸多边形面积的百分比. 分析: 几乎是凸包和多边形面积的裸题. 注意:最后输出的百分号前面有个空格,第一次交P ...

  9. uva 10652 Board Wrapping

    主要是凸包的应用: #include <cstdio> #include <cmath> #include <cstring> #include <algor ...

随机推荐

  1. Sybase:数据库检索的日期格式

    Sybase:数据库检索的日期格式 示例代码: --1,字符转日期 ' as date ),'yyyy/mm/dd'); ---结果:2018/03/09 --2,一年内第几天 ' as date ) ...

  2. java连接zookeeper服务器出现“KeeperErrorCode = ConnectionLoss for /test”

    昨天调试java连接zookeeper服务器,zookeeper搭建过程在这里不做赘述,在创建连接后,然后操作节点一直报异常 错误信息如下: Exception in thread "mai ...

  3. jQuery图片列表拖拽排序布局

    在线演示 本地下载

  4. linux新手学习之Arch Linux入门经验分享

    我一直是以Ubuntu与Fedora作为新手入门的系统,但是其实我真正想推荐的是Arch,经过前面的学习,或许你对Linux已经有了一个大致的了解,现在如果你想加速你的步伐,也许可以看看本文.如果要问 ...

  5. spark学习14(spark local模式运行spark程序的报错)

    报错1 java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries. 解 ...

  6. mac 安装python3

    Python有两个版本,一个是2.x版,一个是3.x版,这两个版本是不兼容的. 现在 Mac 上默认安装的 python 版本为  2.7 版本,若 安装 新版本需要 通过 该地址进行下载: http ...

  7. WebUploader 解决文件多次上传和删除上传文件的问题

    文件多次上传有两种情况: 1. 上传前的多次选择 2. 上传成功后,再次选择 其实API上,已经有了介绍了,不知道为什么有同学还是不知道如何做,我来抛砖引玉吧. 配置项: duplicate {Boo ...

  8. scala学习手记6 - 字符串与多行原始字符串

    scala中的字符串类就是java中的java.lang.String类.不过scala也为String提供了一个富封装类:scala.runtime.RichString. scala可以将java ...

  9. Spring中Bean的生命周期是怎样的

    1.Spring对Bean进行实例化(相当于程序中的new Xx()) 2.Spring将值和Bean的引用注入进Bean对应的属性中 3.如果Bean实现了BeanNameAware接口,Sprin ...

  10. Entity Framework 6 Code First 系列:无需修改实体和配置-在MySql中使用和SqlServer一致的并发控制

    无需修改实体和配置,在MySql中使用和SqlServer一致的并发控制.修改RowVersion类型不可取,修改为Timestamp更不可行.Sql Server的RowVersion生成一串唯一的 ...