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个长方形,用一个面积尽量小的凸多边形把他们围起来 求木板占包装面积的百分比 输入给出长方形的中心坐标,长,宽,以及长方形 ...
随机推荐
- 【BZOJ 2121】字符串游戏
http://www.lydsy.com/JudgeOnline/problem.php?id=2121 dp,设\(f(i,j,k,l)\)表示原串i到j这个子串能否被删成第k个串的长度为l的前缀. ...
- luoguP3600 随机数生成器 期望概率DP + DP优化
这篇题解更像对他人题解的吐槽和补充? 考虑答案 $E[X] = \sum\limits_{i = 1}^{x} i P(X = i)$ $P(X = i)$不好求................(其实 ...
- 【最小割】BZOJ3894-文理分科
[题目大意] 给定一个m*n的矩阵,每个格子的人可以学文或者学理,学文和学理各有一个满意度,如果以某人为中心的十字内所有人都学文或者学理还会得到一个额外满意度,求最大满意度之和. [思路] 发现这道题 ...
- WEB架构师成长之路 一
一 .你必须学习面向对象的基础知识 1.降低软件开发的复杂度 2.提高软件开发的效率 3.提高软件质量:可维护性,可扩展性,可重用性等. 提高软件质量:可维护性,可扩展性,可重用性等,再具体点,就是高 ...
- Codeforces Round #202 (Div. 1) D. Turtles DP
D. Turtles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/problem/B ...
- Redis 3.0 Windows 安装步骤
Redis 3.0 Windows 安装步骤 ----来自 https://www.aliyun.com/jiaocheng/872572.html 发布时间:2018-04-10 来源:网络 上传者 ...
- 如何使用DotNet 2.0中的应用程序配置 Settings.settings
对于桌面应用程序,常常会需要记录一些用户配置信息,早期的做法一般是使用读写INI文件的办法. 对于.NET应用程序,并没有提供直接操作INI文件的类,需要调用Win32API,具体办法可以参考: ...
- 28个Java常用的工具类
源码下载:http://pan.baidu.com/s/1pJLSczD Base64.javaBase64DecodingException.javaCConst.javaCharTools.jav ...
- PHP格式化金钱函数
实现目的: 对数字进行格式化,以类似¥10,000,000的格式输出. 实现方法: function doFormatMoney($money){ $tmp_money = strrev($money ...
- MAC 更新SVN到1.8
经过谷歌和百度N次后,最终搞定SVN的升级,Intellij Idea和Xcode5.1都能够正常使用. 步骤: 1. 下载Subverion的Max安装版.(推荐.使用其它brew和port都试过, ...