UVA 10652 Board Wrapping 计算几何
多边形凸包。。
。。
Description Problem B Board Wrapping Input: standard input 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 InputOn 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 n, 1< OutputFor 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
Swedish National Contest The Sample Input and Sample Output corresponds to the givenpicture Source Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: (Computational) Geometry :: Polygon :: Standard
Root :: AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) :: Chapter 4. Geometry :: Geometric Algorithms in 2D :: Examples Root :: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim) :: (Computational) Geometry :: Polygon - Standard |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector> using namespace std; const double eps=1e-6; int dcmp(double x) { if(fabs(x)<eps) return 0; return (x<0)?-1:1;} struct Point
{
double x,y;
Point(){}
Point(double _x,double _y):x(_x),y(_y){};
}; Point operator+(Point A,Point B) { return Point(A.x+B.x,A.y+B.y);}
Point operator-(Point A,Point B) { return Point(A.x-B.x,A.y-B.y);}
Point operator*(Point A,double p) { return Point(A.x*p,A.y*p);}
Point operator/(Point A,double p) { return Point(A.x/p,A.y/p);} bool operator<(const Point& A,const Point& B) {return dcmp(A.x-B.x)<0||(dcmp(A.x-B.x)==0&&dcmp(A.y-B.y)<0);}
bool operator==(const Point& a,const Point& b) {return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0;} double Angle(Point v){return atan2(v.y,v.x);}
Point Rotate(Point A,double rad) {return Point(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));}
double torad(double deg) {return deg/180.*acos(-1.);}
double Cross(Point A,Point B){return A.x*B.y-A.y*B.x;} int n;
double area0,area1;
vector<Point> vp,ch; // 点集凸包
// 假设不希望在凸包的边上有输入点,把两个 <= 改成 <
// 注意:输入点集会被改动
vector<Point> CovexHull(vector<Point>& p)
{
sort(p.begin(),p.end());
p.erase(unique(p.begin(),p.end()),p.end());
int n=p.size();
int m=0;
vector<Point> ch(n+1);
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--;
ch.resize(m);
return ch;
} double PolygonArea(vector<Point>& p)
{
int n=p.size();
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 main()
{
int T_T;
scanf("%d",&T_T);
while(T_T--)
{
scanf("%d",&n);
area0=area1=0.0;
vp.clear();
double x,y,w,h,j;
for(int i=0;i<n;i++)
{
scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&j);
area0+=w*h;
double rad=torad(j);
Point o(x,y);
vp.push_back(o+Rotate(Point(w/2,h/2),-rad));
vp.push_back(o+Rotate(Point(-w/2,h/2),-rad));
vp.push_back(o+Rotate(Point(w/2,-h/2),-rad));
vp.push_back(o+Rotate(Point(-w/2,-h/2),-rad));
}
ch=CovexHull(vp);
area1=PolygonArea(ch);
printf("%.1lf %%\n",100.*area0/area1);
}
return 0;
}
UVA 10652 Board Wrapping 计算几何的更多相关文章
- Uva 10652 Board Wrapping(计算几何之凸包+点旋转)
题目大意:给出平面上许多矩形的中心点和倾斜角度,计算这些矩形面积占这个矩形点形成的最大凸包的面积比. 算法:GRAHAM,ANDREW. 题目非常的简单,就是裸的凸包 + 点旋转.这题自己不会的地方就 ...
- uva 10652 Board Wrapping (计算几何-凸包)
Problem B Board Wrapping Input: standard input Output: standard output Time Limit: 2 seconds The sma ...
- UVA 10652 Board Wrapping(凸包)
The small sawmill in Mission, British Columbia, hasdeveloped a brand new way of packaging boards for ...
- ●UVA 10652 Board Wrapping
题链: https://vjudge.net/problem/UVA-10652 题解: 计算几何,Andrew求凸包, 裸题...(数组开小了,还整了半天...) 代码: #include<c ...
- 简单几何(向量旋转+凸包+多边形面积) UVA 10652 Board Wrapping
题目传送门 题意:告诉若干个矩形的信息,问他们在凸多边形中所占的面积比例 分析:训练指南P272,矩形面积长*宽,只要计算出所有的点,用凸包后再求多边形面积.已知矩形的中心,向量在原点参考点再旋转,角 ...
- uva 10652 Board Wrapping
主要是凸包的应用: #include <cstdio> #include <cmath> #include <cstring> #include <algor ...
- UVA 10652 Board Wrapping(凸包)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32286 [思路] 凸包 根据角度与中心点求出长方形所有点来,然后就 ...
- UVA 10652 Board Wrapping(二维凸包)
传送门 刘汝佳<算法竞赛入门经典>P272例题6包装木板 题意:有n块矩形木板,你的任务是用一个面积尽量小的凸多边形把它们抱起来,并计算出木板占整个包装面积的百分比. 输入:t组数据,每组 ...
- uva 10625 Board Wrapping
https://vjudge.net/problem/UVA-10652 给出n个长方形,用一个面积尽量小的凸多边形把他们围起来 求木板占包装面积的百分比 输入给出长方形的中心坐标,长,宽,以及长方形 ...
随机推荐
- [JOBDU1172]哈夫曼树
题目大意: 给你一堆权值,求这些权值建成哈夫曼树后的WPL. 思路: 哈夫曼树的WPL等于各非叶子结点权值之和. 所以直接贪心模拟构建哈夫曼树的过程. 先把所有的权值放在一个堆中,然后每次取里面最小的 ...
- Markdown---锚点使用
Markdown目前还没有支持文内锚点的标记语法:但是支持html,所以锚点可以通过html语法来实现 使用方法 <a href='#jump'>第一个题目</a> 带有锚点的 ...
- ngxin error日志
日志模块ngx_errlog_module对于支持可变参数平台提供的三个接口 #define ngx_log_error(level, log, ...) \ if ((log)->log_le ...
- 实用在线小工具 -- JS代码压缩工具
实用在线小工具 -- JS代码压缩工具 将JS代码进行压缩可以减少内存占用,下面链接是一个在线JS代码压缩工具,它将多余的空格和换行符压缩了. JS代码压缩工具链接:http://jspack ...
- VK Cup 2016 - Qualification Round 2 A. Home Numbers 水题
A. Home Numbers 题目连接: http://www.codeforces.com/contest/638/problem/A Description The main street of ...
- centos安装gcc
1.安装gcc基本开发工具环境 yum groupinstall 'Development Tools' 2.安装完成后查看安装是否成功 whereis gcc 3.查看gcc版本 gcc --ver ...
- CentOS 6.9开启iptables的日志实现调试
系统日志配置在CentOS 5上叫syslog,而在CentOS 6上叫rsyslog(增强版的syslog),CentOS 5上的配置文件在/etc/syslog.conf下,而CentOS 6在/ ...
- Apple Developer申请成功
上周日白天,我去申请了Apple Developer.我先是在百度上浏览了一些经验教程,但是点进苹果开发者官网时却发现完全不是那么一回事.盖因它的页面经常在变,如同现在苹果在主推tvOS这个对中国用户 ...
- HDU 4675 GCD of Sequence (2013多校7 1010题 数学题)
GCD of Sequence Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)T ...
- The useful App Paths registry key : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths how to load BPLs without writ ...