题意:

有n块互不重叠的矩形木板,用尽量小的凸多边形将它们包起来,并输出并输出木板总面积占凸多边形面积的百分比。

分析:

几乎是凸包和多边形面积的裸题。

注意:最后输出的百分号前面有个空格,第一次交PE了。

用printf打印%,可以连续打印两个%%,printf("%%\n");   这个冷知识记得以前学过,不过不用也就忘了。

学习一下vector容器中去重的小技巧。

sort(p.begin(), p.end());
p.erase(unique(p.begin(), p.end()), p.end());

ConvexHull函数最后用到了resize(n),顾名思义就是改变容器的大小为n。超过该范围的元素无效,下次push_back进来的元素将在第n个后面。

 //#define LOCAL
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std; const double PI = acos(-1.0); struct Point
{
double x, y;
Point(double x=, double y=):x(x), y(y){}
};
typedef Point Vector;
Point operator + (Vector A, Vector B) { return Vector(A.x+B.x, A.y+B.y); }
Point operator - (Vector A, Vector B) { return Vector(A.x-B.x, A.y-B.y); }
double Cross(const Vector& A, const Vector& B) { return A.x*B.y - A.y*B.x; }
Vector Rotate(Vector A, double p)
{
return Vector(A.x*cos(p)-A.y*sin(p), A.x*sin(p)+A.y*cos(p));
}
bool operator < (const Point& A, const Point& B)
{
return A.x < B.x || (A.x == B.x && A.y < B.y);
}
bool operator == (const Vector& A, const Vector& B)
{
return A.x == B.x && A.y == B.y;
} double torad(double x) { return x / 180.0 * PI; } vector<Point> ConvexHull(vector<Point> p)
{
//Ô¤´¦Àí£¬È¥ÖØ
sort(p.begin(), p.end());
p.erase(unique(p.begin(), p.end()), p.end()); int n = p.size();
int m = ;
vector<Point> ch(n+);
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--;
ch.resize(m);
return ch;
} double PolygonArea(vector<Point> p)
{
int n = p.size();
double ans = 0.0;
for(int i = ; i < n-; ++i)
ans += Cross(p[i]-p[], p[i+]-p[]);
return ans/;
} int main(void)
{
#ifdef LOCAL
freopen("10652in.txt", "r", stdin);
#endif int T;
scanf("%d", &T);
while(T--)
{
int n;
vector<Point> p;
double area1 = 0.0;
scanf("%d", &n);
for(int i = ; i < n; ++i)
{
double x, y, w, h, a;
scanf("%lf%lf%lf%lf%lf", &x, &y, &w, &h, &a);
Point o(x, y);
double ang = -torad(a);
p.push_back(o + Rotate(Vector(w/, h/), ang));
p.push_back(o + Rotate(Vector(-w/, h/), ang));
p.push_back(o + Rotate(Vector(w/, -h/), ang));
p.push_back(o + Rotate(Vector(-w/, -h/), ang));
area1 += w*h;
}
double area2 = PolygonArea(ConvexHull(p));
printf("%.1lf %%\n", area1 / area2 * 100.0);
}
}

代码君

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 计算几何

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

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

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

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

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

  5. UVA 10652 Board Wrapping(凸包)

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

  6. UVA 10652 Board Wrapping(凸包)

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

  7. UVA 10652 Board Wrapping(二维凸包)

    传送门 刘汝佳<算法竞赛入门经典>P272例题6包装木板 题意:有n块矩形木板,你的任务是用一个面积尽量小的凸多边形把它们抱起来,并计算出木板占整个包装面积的百分比. 输入:t组数据,每组 ...

  8. uva 10652 Board Wrapping

    主要是凸包的应用: #include <cstdio> #include <cmath> #include <cstring> #include <algor ...

  9. ●UVA 10652 Board Wrapping

    题链: https://vjudge.net/problem/UVA-10652 题解: 计算几何,Andrew求凸包, 裸题...(数组开小了,还整了半天...) 代码: #include<c ...

随机推荐

  1. 【转】如何设置Android软键盘的默认不弹出?

    在开发Anroid的时候,当你打开一个界面的时候,屏幕的焦点会自动停留在第一个EditText中,Android的软键盘默认会自动弹出,用户第一眼连界面都没有看清楚,软键盘就弹出来了,这就影响到了用户 ...

  2. C#系统缓存全解析

    原文:http://blog.csdn.net/wyxhd2008/article/details/8076105 目录(?)[-] 系统缓存的概述 页面输出缓存 页面局部缓存 文件缓存依赖 数据库缓 ...

  3. angular入门系列教程3

    主题: 本篇主要目的就是继续完善home页,增加tab导航的三个页index index1 index2 效果图: 细节: 初始化的JS就是咱们的home.js,仔细来看. angular的route ...

  4. SVN检出资源文件

    一.选择new,输入svn,点击“从SVN检出项目” 二.选择“创建新的资源库位置”或“使用现有的资源库位置”(如果是新建,则需要地址和用户名.密码) 三.从现有的资源库选中项目

  5. Mysql创建和删除用户

    问题描述:        Mysql中创建用户和删除用户 问题解决:     (1)查询Mysql当前登录账户     (2)创建用户     方法一: 创建用户赋予用户所有权限: 新创建的用户可以在 ...

  6. 如何通过CSS3实现背景图片色彩的梯度渐变

    随着网站的越来越普及,CSS3和HTML5必将成为网站前端发展的主流方向,特别是在移动端,高端浏览器给前端工程师们带来了无以言表的体验. 通俗的来讲,CSS3可以说是CSS技术的升级版本,CSS3语言 ...

  7. Java多线程——<六>更方便的线程

    一.概述 标题很抽象,什么叫更方便?更是相比谁来说的呢? 原来,我们定义任务,都是实现自Runnable或者Callable接口,但是这样必然需要你将新定义的任务附着给线程,然后再调用线程启动.在不考 ...

  8. 查看 dmp 字符集

    用Oracle的exp工具导出的dmp文件也包含了字符集信息,dmp文件的第2和第3个字节记录了dmp文件的字符集.如果dmp文件不大,比如只有几M或几十M,可以用UltraEdit打开(16进制方式 ...

  9. mysql导出多个表数据为excel方法,substring函数查询

    //查询sys_username以S.00655开头的用户 ),sys_password FROM `tbl_sa_syslogin` where sys_username like 'S.%'; / ...

  10. Linux shell 脚本小记

    if结构 #!/bin/env bash -gt ] then echo "$1 is positive" -lt ] then echo "$1 is negative ...