UVA 10652 凸包问题
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std; const double eps = 1e-;
const int N = ;
int dcmp(double x)
{
if(abs(x) < eps) return ;
if(x < ) return -;
else return ;
} struct Point{
double x,y;
Point(double x = ,double y = ):x(x),y(y){}
bool operator<(const Point &m)const{
return dcmp(x - m.x) < || (dcmp(x - m.x) == && dcmp(y - m.y) < );
} bool operator==(const Point &m)const{
return dcmp(x - m.x) == && dcmp(y - m.y) == ;
}
}; Point ch[N<<],p[N<<]; 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 b)
{
return Vector(a.x * b , a.y * b);
} Vector operator/(Vector a , double b)
{
return Vector(a.x / b , a.y/b);
} double Cross(Vector a , Vector b)
{
return a.x * b.y - a.y * b.x;
} Vector GetReverse(Vector a , double rad)
{
double x = a.x * cos(rad) - a.y * sin(rad);
double y = a.x * sin(rad) + a.y * cos(rad);
return Vector(x,y);
}
//计算多边形面积
double ConvexPolygonArea(Point *p , int n)
{
double area = ;
for(int i=;i<n-;i++){
area += Cross(p[i] - p[] , p[i+] - p[]);
}
return area / ;
}
//求形成凸包的最大范围
int ConvexHull(Point *p, int n, Point *ch) //凸包
{
sort(p, p+n);
n = unique(p, p+n) - p; //去重
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;
}
int main()
{
// freopen("test.in","rb",stdin); int T,n;
double x,y,w,h,_angle; //_angle表示度数,自己还要转化成弧度
scanf("%d",&T);
while(T--){
scanf("%d",&n);
int k=;
double area = ;
for(int i=;i<n;i++)
{
scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&_angle);
area += w*h;
double rad = -_angle * acos(-) / ;
Point o(x,y);
//cout<<" rad: "<<rad<<endl;
p[k++] = GetReverse(Vector(-w/ , h/),rad) + o;
p[k++] = GetReverse(Vector(w/ , h/),rad) + o;
p[k++] = GetReverse(Vector(w/ , -h/),rad) + o;
p[k++] = GetReverse(Vector(-w/ , -h/),rad) + o;
} int m = ConvexHull(p , k , ch);
double sumOfArea = ConvexPolygonArea(ch , m);
double ans = area / sumOfArea * ; printf("%.1f %%\n",ans);
}
return ;
}
UVA 10652 凸包问题的更多相关文章
- 简单几何(向量旋转+凸包+多边形面积) UVA 10652 Board Wrapping
题目传送门 题意:告诉若干个矩形的信息,问他们在凸多边形中所占的面积比例 分析:训练指南P272,矩形面积长*宽,只要计算出所有的点,用凸包后再求多边形面积.已知矩形的中心,向量在原点参考点再旋转,角 ...
- UVa 10652 (简单凸包) Board Wrapping
题意: 有n块互不重叠的矩形木板,用尽量小的凸多边形将它们包起来,并输出并输出木板总面积占凸多边形面积的百分比. 分析: 几乎是凸包和多边形面积的裸题. 注意:最后输出的百分号前面有个空格,第一次交P ...
- UVA 10652 Board Wrapping(凸包)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32286 [思路] 凸包 根据角度与中心点求出长方形所有点来,然后就 ...
- Uva 10652 Board Wrapping(计算几何之凸包+点旋转)
题目大意:给出平面上许多矩形的中心点和倾斜角度,计算这些矩形面积占这个矩形点形成的最大凸包的面积比. 算法:GRAHAM,ANDREW. 题目非常的简单,就是裸的凸包 + 点旋转.这题自己不会的地方就 ...
- UVA 10652 Board Wrapping(凸包)
The small sawmill in Mission, British Columbia, hasdeveloped a brand new way of packaging boards for ...
- uva 10652 Board Wrapping (计算几何-凸包)
Problem B Board Wrapping Input: standard input Output: standard output Time Limit: 2 seconds The sma ...
- UVA 10652 Board Wrapping(二维凸包)
传送门 刘汝佳<算法竞赛入门经典>P272例题6包装木板 题意:有n块矩形木板,你的任务是用一个面积尽量小的凸多边形把它们抱起来,并计算出木板占整个包装面积的百分比. 输入:t组数据,每组 ...
- UVa 10652(旋转、凸包、多边形面积)
要点 凸包显然 长方形旋转较好的处理方式就是用中点的Vector加上旋转的Vector,然后每个点都扔到凸包里 多边形面积板子求凸包面积即可 #include <cstdio> #incl ...
- UVa 10256 凸包简单应用
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- ssrs 2016, mobile report error: The report may be misconfigured, the data may not be available, or the server version may be unsupported.
使用多账户配置ssrs mobile report 权限后,使用客户端显示: 使用web 查阅,显示: 遇到这种情况,可能是由于,report引用了 数据集文件夹中的数据集,请记得把数据集文件夹上为该 ...
- ECMAScript6之箭头函数
2015年6月17日,ECMAScript 6发布正式版本,即ECMAScript 2015. 函数作为js语言中的一等公民.自然Es6中推出的箭头函数(=>)也是备受瞩目的.那我们接下来看下传 ...
- vba根据部门分别汇总不同部门下的人员不同培训内容的时长总计,多条件求和
Option Explicit Sub yy() Dim d, arr, s$, i&, m&, w$ Set d = CreateObject("Scripting.Dic ...
- SCHTASKS /CREATE
SCHTASKS "/" 这个符号前要加个空格才能运行成功 ,搞半天!
- zabbix企业应用之windows系统安装omsa硬件监控
具体请参考 作者:dl528888http://dl528888.blog.51cto.com/2382721/1421335 大致 1.安装OMSA http://zh.community.de ...
- [分享] IMX6嵌入式开发板linux QT挂载U盘及TF卡
本文转自迅为开发板:http://www.topeetboard.com 开发平台:iMX6开发板 linux QT 系统下挂载 u 盘如下图所示,qt 启动之后,在超级终端中使用命令“mknod / ...
- Divide and Conquer_1.最大连续子数组
给定一个数组,求它的一个子数组,使其求和最大. 这个问题的应用:给定一只股票很多天的价格,计算从哪天买进哪天卖出能获得最大利润. 给定 prices:100 113 98 87 65 ...
- jQuery 首页搜索区域模块随页面滑动而变化
/*搜索区块的颜色变化*/ function search(){ var searchBox = document.querySelector('.m_head'); var bannerBox = ...
- 卸载钩子 UnhookWindowsHookEx
The UnhookWindowsHookEx function removes a hook procedure installed in a hook chain by the SetWindow ...
- Windows:32位程序运行在64位系统上注册表会重定向
参考资料 微软注册表英文文档 StackOverflow社区回答 1.注册表位置 64bit系统(Windows Server 2008 R2只有64bit系统)的注册表分32 位注册表项和64位注册 ...