题目链接: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(double deg) { return deg/ * PI; } //角度化弧度 struct Pt {
double x,y;
Pt(double x=,double y=):x(x),y(y) {};
};
typedef Pt vec;
vec operator - (Pt A,Pt B) { return vec(A.x-B.x,A.y-B.y); }
vec operator + (vec A,vec B) { return vec(A.x+B.x,A.y+B.y); }
bool operator < (const Pt& a,const Pt& b) {
return a.x<b.x || (a.x==b.x && a.y<b.y);
} double cross(Pt A,Pt B) { return A.x*B.y-A.y*B.x; }
vec rotate(vec A,double rad) {
return vec(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
} int ConvexHull(Pt* p,int n,Pt* ch) {
sort(p,p+n);
int m=;
for(int i=;i<n;i++) {
while(m> && cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--; //维护凸包
ch[m++]=p[i];
}
int k=m;
for(int i=n-;i>=;i--) {
while(m>k && cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
if(n>) m--;
return m;
} double PolygonArea(Pt* p,int n) { //多边形面积
double S=;
for(int i=;i<n-;i++)
S += cross(p[i]-p[],p[i+]-p[]);
return S/;
} const int N = +;
Pt P[N],ch[N];
int n; int main() {
int T;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
int pc=; double S1=;
double x,y,w,h,j;
for(int i=;i<n;i++) {
scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&j);
double ang=-torad(j);
Pt o(x,y);
P[pc++]= o + rotate(vec(-w/,-h/),ang);
P[pc++]= o + rotate(vec(w/,-h/),ang);
P[pc++]= o + rotate(vec(-w/,h/),ang);
P[pc++]= o + rotate(vec(w/,h/),ang);
S1 += w*h;
}
int m=ConvexHull(P,pc,ch);
double S2=PolygonArea(ch,m);
printf("%.1lf %%\n",S1*/S2);
}
return ;
}

UVA 10652 Board Wrapping(凸包)的更多相关文章

  1. UVA 10652 Board Wrapping(凸包)

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

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

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

  3. UVA 10652 Board Wrapping 计算几何

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

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

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

  5. Uva 10652 Board Wrapping(计算几何之凸包+点旋转)

    题目大意:给出平面上许多矩形的中心点和倾斜角度,计算这些矩形面积占这个矩形点形成的最大凸包的面积比. 算法:GRAHAM,ANDREW. 题目非常的简单,就是裸的凸包 + 点旋转.这题自己不会的地方就 ...

  6. UVA 10652 Board Wrapping(二维凸包)

    传送门 刘汝佳<算法竞赛入门经典>P272例题6包装木板 题意:有n块矩形木板,你的任务是用一个面积尽量小的凸多边形把它们抱起来,并计算出木板占整个包装面积的百分比. 输入:t组数据,每组 ...

  7. uva 10652 Board Wrapping

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

  8. ●UVA 10652 Board Wrapping

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

  9. uva 10625 Board Wrapping

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

随机推荐

  1. 基于ACE的定时器模板类

    ACETimerClockGenerator.h ClockGeneratorIF.h 在类中定义一个结构体,在结构体中定义一个函数. 在结构体中定义一个函数,这样做有什么好呢? TimerHandl ...

  2. yum 安装 依赖报错

    今天使用yum安装的时候 报错: Error: Multilib version problems found. This often means that the root cause 应该是yum ...

  3. leetcode problem (2-4)

    Problem 2 --- Add Two Numbers 简单的模拟题. Problem 3 --- Longest Substring Without Repeating Characters 题 ...

  4. wap开发之滑动事件(swipe、tap、swipeleft、swiperight)等

    最近一直找在wap端可以实现的swipe等滑动事件的方法,开始研究了jquery-mobile,zepto,结果由于jqm太大.zepto有不少缺陷.为此研究了zepto,想把里面的swipe事件独立 ...

  5. BinaryReader 和BinaryWriter 读写类对象

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  6. 服务器慢 mysql-bin.000001文件占满磁盘的原因与解决

    发现 VPS 服务器上的网站反应超级慢,简单的重启.重启各主要服务,发现mysql 的反应极其不正常. 一方面是问题,这与站点访问量有关.开始时从mysql 的配置文件 my.cnf 考虑,但志文工作 ...

  7. App页面显示优化

    在开发移动端APP页面时,对各操作系统各种型号的手机进行适配是必须的.然鹅,上周在开发完一个落地页后,被测试给打了回来,其中列出了一个在我看来很小的问题:单击进入页面的时候,页面还没加载完的时候字体显 ...

  8. leetcode第八题 String to Integer (atoi) (java)

    String to Integer (atoi) time=272ms   accepted 需考虑各种可能出现的情况 public class Solution { public int atoi( ...

  9. 【UVA 1151】 Buy or Build (有某些特别的东东的最小生成树)

    [题意] 平面上有n个点(1<=N<=1000),你的任务是让所有n个点连通,为此,你可以新建一些边,费用等于两个端点的欧几里得距离的平方. 另外还有q(0<=q<=8)个套餐 ...

  10. CAS实现单点登录方案(SSO完整版)

    一.简介 1.cas是由耶鲁大学研发的单点登录服务器 2.本教材所用环境 Tomcat7.2 JDK1.7 CAS Service 版本    cas-server-3.4.8-release CAS ...