首页 > 其他分享 >UVA10652 Board Wrapping 题解

UVA10652 Board Wrapping 题解

时间:2023-11-18 17:36:32浏览次数:41  
标签:rad ch return UVA10652 题解 Wrapping Vector double 向量

Link

UVA10652 Board Wrapping

Question

给出 \(N\) 个矩形,求面积最小的凸多边形能包住所有矩形

求 矩形面积占凸多边形面积的百分比

Solution

把矩形的四个顶点拿出来,就可以转化成凸包裸题了

Code

#include<bits/stdc++.h>
using namespace std;

const double eps=1e-9;
const double PI=3.14159;
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 - (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};} //向量/数=向量

//向量逆时针旋转 rad
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 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;} //叉积
int dcmp(double x){if(fabs(x)<eps) return 0;else return x<0?-1:1;}  //自定义比较函数
double ConvexPolgonArea(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;
}
bool cmp(Point A,Point B){return A.x<B.x||(dcmp(A.x-B.x)==0&&A.y<B.y);}
int ConvexHull(Point* p,int n,Point* ch){ // 凸包
    sort(p,p+n,cmp);
    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 torad(double degrees) {return degrees*PI/180.0;}
int main(){
    freopen("10652.in","r",stdin);
    int T;
    Point P[2500],ch[2500];
    scanf("%d",&T);
    while(T--){
        int n,pc=0;
        double area1=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            double x,y,w,h,j,ang;
            scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&j);
            Point o(x,y);
            ang=-torad(j);
            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;
        }
        sort(P,P+n,cmp);
        int m=ConvexHull(P,pc,ch);
        double area2=ConvexPolgonArea(ch,m);
        printf("%.1lf %%\n",area1*100/area2);
    }
    return 0;
}

标签:rad,ch,return,UVA10652,题解,Wrapping,Vector,double,向量
From: https://www.cnblogs.com/martian148/p/17840775.html

相关文章

  • NEFU OJ Problem1487 时空乱流题解
    时空乱流Problem:ETimeLimit:1500msMemoryLimit:65535KDescription星际飞行员Alice在一次航行中遭遇了时空乱流,时空乱流将导致Alice乘坐的飞船在n个位面之间穿梭。星际宇航局管理员Bob收到了Alice的求救信号,决定在某些位面上设立监测站,当Alice进入某个已经设立监......
  • 关于maven构建tomcat服务器一直启动不了的问题解决
    以往我都是创建maven项目后自己去配置web,再通过自己配置以下信息之后,配置tomcat。最终结果是始终报错 之后摸索发现,可以在maven项目配置前将以上“maven主路径,用户设置文件,本地仓库”信息确定好。 在弹出的页面设置好后,再创建maven项目便省时很多,tomcat配置后可以使用 ......
  • 【HDU 1276】士兵队列训练问题 题解(链表+模拟)
    某部队进行新兵队列训练,将新兵从一开始按顺序依次编号,并排成一行横队,训练的规则如下:从头开始一至二报数,凡报到二的出列,剩下的向小序号方向靠拢,再从头开始进行一至三报数,凡报到三的出列,剩下的向小序号方向靠拢,继续从头开始进行一至二报数。。。,以后从头开始轮流进行一至二报数、一至......
  • T399753 counting problem(计数问题)题解
    LinkT399753countingproblem(计数问题)Question给出一个正整数\(n\),求\(AB+CD=n\)的方案数,\(A,B,C,D\)都是要求是正整数Solution考虑直接枚举\(ABCD\)显然是不切实际的那么就折半枚举设\(F_i\)表示两个数的乘积为\(i\)的方案数答案就是\(\sum\limits_{i=1......
  • T399750 Cell kingdom(Hard) 题解
    LinkT399750Cellkingdom(Hard)Qustion第一天产生\(1\)个细胞,之后的每一天,一个细胞都会分裂成\(8\)个和自己一样的细胞,每个细胞在第三天都会自爆并且带走当天产生的\(6\)个细胞,求第\(x\)天有多少细胞Solution我们设\(F[i]\)表示第\(i\)天产生的新细胞个数那么可......
  • T399742 Ting'er loves traveling 题解
    LinkT399742Ting'erlovestravelingQuestion给出一个图,使得\(1\)到\(N\)的路径上的最大值最小Solution看到最大值最小想到二分,二分最大值\(top\)然后去check验证能不能从\(1\)走到\(N\)Code#include<bits/stdc++.h>#defineintlonglongusingnamespacest......
  • 前端页面部署之后刷新页面之后出现HTTP 错误 404.0 - Not Found错误问题解决
    前端页面部署能正常访问,但是一旦刷新页面就报如下错误:404.0-NotFound 解决办法:下载IISURL重写模版,并安装。下面为安装地址:URLRewrite:TheOfficialMicrosoftIISSite安装之后IIS中出现如下IIS重写模块:点击进去添加规则,添加空白规则:  配置好之后会自动生成we......
  • T399751 Liangle's Rose Problem(亮亮的玫瑰问题)题解
    LinkT399751Liangle'sRoseProblem(亮亮的玫瑰问题)Question给出一个数组\(a\),有\(Q\)次询问,每次询问\([L,R]\)种随便挑选几个连续的\(a_i\)使得,他们几个的或的值最大Solution考虑贪心,如果把负数视为\(0\),那么一个数或上另外一个数,数肯定是变大的,那么就应该或上\(......
  • T399752 The Maze of the Imperial Sister(御姐的迷宫)题解
    LinkT399752TheMazeoftheImperialSister(御姐的迷宫)Question判断图内是否有环Solution先判断连通性,所有点是不是在一个块内,然后用树的性质,点数\(=\)边数\(+1\)判断Code#include<bits/stdc++.h>usingnamespacestd;constintmaxn=1e5+5,maxe=maxn*2;structI......
  • P4115 Qtree4 题解
    P4115看到单点修改,求全局白色的最远距离,可以使用点分树。考虑维护这棵点分树,想想树的直径的dp求法:\(f_u=\max\{f_v+w(u,v)\}\),答案为\(\max(f_v+f_{v'})(v,v'\in\{\text{son}_u\})\),\(\{\text{son}_i\}\)表示\(i\)的孩子集合。这时候维护就十分简单了,对于每个点都......