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个长方形,用一个面积尽量小的凸多边形把他们围起来 求木板占包装面积的百分比 输入给出长方形的中心坐标,长,宽,以及长方形 ...
随机推荐
- scanf输入字符串相关
http://blog.csdn.net/liuhui_8989/article/details/13398793 补充..输入s的时候不要把变量设置成string类型,设置成char数组类型.. ...
- Java编程思想学习(五)----第5章:初始化与清理
随着计算机革命的发展,“不安全”的编程方式已逐渐成为编程代价高昂的主因之一. C++引入了构造嚣(constructor)的概念,这是一个在创建对象时被自动调用的特殊方法.Java中也采用了构造器,并 ...
- 【原】Eclipse更改字符编码,精华版
- Codeforces Round #346 (Div. 2) A. Round House 水题
A. Round House 题目连接: http://www.codeforces.com/contest/659/problem/A Description Vasya lives in a ro ...
- mysql数据库文件简介和应用
存放目录: 用 whereis my.cnf 查看mysql配置文件的目录,查看my.cnf的datadir参数可找到mysql数据库文件的存放目录. 本机存放的目录为/var/lib/mysql,进 ...
- asp.net连接LDAP数据,并从LDAP中取出相关数据(1)
ASP.NET连接LDAP数据库的有关信息 一.封装在DAL层中的获取用户信息的函数 /// <summary> /// 按照用户Id查找用户信息 /// </summary> ...
- undefined null 各种值比较(面试题)
undefined和null与任何有意义的值比较返回的都是false,但是null与undefined之间互相比较返回的是true. console.log(null == false); //fal ...
- 谈谈SQL server的 worker threads-----微软亚太区数据库技术支持组 官方博客
https://blogs.msdn.microsoft.com/apgcdsd/2012/11/27/sql-server-worker-threads/
- 220V和380V电器设备电流计算方法
220V和380V电器设备电流计算方法 1)单相电机电流=功率/(电压*功率因数*效率): 2)三相电机电流=功率/(1.732*电压*功率因数*效率): 3)空载电流为额定电流的30-50%左右: ...
- 破解NET的四大神器[转]
原本这篇文章可以更早一星期写出来与大家分享,由于某方面的原因耽搁到现在,心里竟有那么一点好像对不住大家的感觉.这当然与神器有关,因为我发现利用这四大神器我似乎觉得几乎所有的NET程序破解都不在话下了 ...