传送门

刘汝佳《算法竞赛入门经典》P272例题6包装木板

题意:有n块矩形木板,你的任务是用一个面积尽量小的凸多边形把它们抱起来,并计算出木板占整个包装面积的百分比。

输入:t组数据,每组先输入木板个数n,接下来n行,每行x,y,w,h,j。(x,y)是木板中心的坐标,w是宽,h是高,j是顺时针旋转的角度。

   木板互不相交。

输出:对于每组数据,输出木板总面积占包装总面积的百分比,保留小数点后1位。

题解:典型的二维凸包问题,理解并调用模板即可。

附上凸包的证明过程,只看网址里的图,注意sort是极角排序:传送门

#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
using namespace std;
typedef struct Point{
double x,y;
Point(double x=,double y=):x(x),y(y){}
}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);
}
bool operator <(const Point &a,const Point &b)
{
return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
double Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
}
Vector Rotate(Vector A,double rad) //向量旋转
{
return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
double ConvexPolygonArea(Point *p,int n)
{
double area=;
for(int i=;i<n-;i++)
area+=Cross(p[i]-p[],p[i+]-p[]);
return area/;
}
double torad(double deg)
{
return deg/*acos(-);
}
int ConvexHull(Point *p,int n,Point* ch) //注意是*ch
{
sort(p,p+n);
//不知道这里为什么不能加unique函数
//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;//别忘了加m
}
int main()
{
int T;
Point P[],ch[];
scanf("%d",&T);
while(T--)
{
int n,pc=;
double area1=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
double x,y,w,h,j,ang;
scanf("%lf%lf%lf%lf%lf",&x,&y,&w,&h,&j);
Point o(x,y);
ang=-torad(j);
P[pc++]=o+Rotate(Vector(-w/,-h/),ang);
P[pc++]=o+Rotate(Vector(w/,-h/),ang);
P[pc++]=o+Rotate(Vector(-w/,h/),ang);
P[pc++]=o+Rotate(Vector(w/,h/),ang);
area1+=w*h; //矩形总面积
}
int m=ConvexHull(P,pc,ch);
double area2=ConvexPolygonArea(ch,m); //凸包面积
//%被看做是格式说明符 所以要输出两个百分号
printf("%.1lf %%\n",area1*/area2);
}
return ;
}

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

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

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

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

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

  3. UVA 10652 Board Wrapping 计算几何

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

  4. UVA 10652 Board Wrapping(凸包)

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

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

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

  6. UVA 10652 Board Wrapping(凸包)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32286 [思路] 凸包 根据角度与中心点求出长方形所有点来,然后就 ...

  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. 使用Graham扫描法求二维凸包的一个程序

    #include <iostream> #include <cstring> #include <cstdlib> #include <cmath> # ...

随机推荐

  1. php精华之独孤九剑

    首先分享一个地址 https://segmentfault.com/a/1190000013696265(这个是主要的分享,人家作者写的非常棒

  2. python版opencv:如何用笔记本摄像头拍照保存

    因为需要制作制作数据集 所以需要在笔记本上外置了一个logi的摄像头 准备使用python上得opencv来进行拍照 环境:opencv+pycharm+win10+py3 #coding:utf-8 ...

  3. 第三章习题 C++ Primer 第六版

    1.使用一个整数输入自己的身高(单位为cm),并将此身高转化为米和厘米共同表示的形式,使用下划线字符来指示输入的位置,使用一个const符号常量来表示转换因子. #include<iostrea ...

  4. [Bzoj1037][ZJOI2008]生日聚会(DP)

    Description 题目链接 Solution 这题状态比较难想, \(dp[i][j][g][h]\)表示强i个人有j个男生,在某个区间男生最多比女生多g人,女生最多比男生多h人的方案数,然后D ...

  5. 总结 Date 2017.09.23

    总结 Date 2017.09.23 <1>统计数字 某次科研调查时得到了n个自然数,每个数均不超过1500000000(1.5*10^9).已知不相同的数不超过10000个,现在需要统计 ...

  6. Android MultiType第三方库的基本使用和案例+DiffUtil的简单用法

    1.MultiType简单介绍 1.1.MultiType用于比较复杂的页面. 如下图,今日头条用到了MultiType处理各种复杂的页面.    这种还是比较简单的类型.因为一个页面也就这种类型. ...

  7. html+css调用服务器端字体

    在浏览网页时,由于客户端没有安装某些特殊字体,导致网页文字无法按设计正常显示,这时我们可以使用服务器字体来避免这种现象的发送 语法 @font-face { /* 自定义字体名称 */ font-fa ...

  8. Centos 7.X 安装JDK1.8

    一.查看本机jdk版本并卸载原有openjdk        查看       # java -version       openjdk version "1.8.0_144"  ...

  9. python学习总结----时间模块 and 虚拟环境(了解)

    time - sleep:休眠指定的秒数(可以是小数) - time:获取时间戳 # 获取时间戳(从1970-01-01 00:00:00到此刻的秒数) t = time.time() print(t ...

  10. springboot13 Hikari 和Introspector

    SpringBoot Initializr Introspector(内省) class TestReflect { @Test fun testReflect() { //获取字节码对象 val c ...