题意:

有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 解决启动页面加载图片空白以及去掉标题栏

    有时候启动页面根据白天晚上来启动时实现加载不同的图片效果,但是加载时会出现短暂的空白,解决方法如下: android:theme="@android:style/Theme.Transluc ...

  2. android studio 不能在线更新android SDK Manager问题解决办法

    Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml, reason: Connecti ...

  3. [转载+原创]Emgu CV on C# (六) —— Emgu CV on Canny边缘检测

    Canny边缘检测也是一种边缘检测方法,本文介绍了Canny边缘检测的函数及其使用方法,并利用emgucv方法将轮廓检测解算的结果与原文进行比较. 图像的边缘检测的原理是检测出图像中所有灰度值变化较大 ...

  4. IP地址格式控制

    /// <summary> /// 验证IP格式是否输入正确 /// </summary> /// <param name="ip"></ ...

  5. CC150 上面重要的题目总结

    第一章 : 全部重要 (1.6, 1.7 Leetcode上有). 1.5 面A碰到 (string compression) 1.7面Z碰到 (set 0) 1.8面Bigfish碰到 (strin ...

  6. POJ1258Agri-Net

    http://poj.org/problem?id=1258 题意 : john当上了镇长,打算给每个农场都连接网络,需要用最小的成本连接其他所有农场,所以要找最少的纤维连在一起,任何两个农场之间的距 ...

  7. Web中的监听器【Listener】

    Servlet监听器:Servlet规范中定义的一种特殊类,它用于监听Web应用程序中的ServletContext.HttpSession和ServletRequest等域对象的创建与销毁事件,以及 ...

  8. 获取其他进程中ListBox和ComboBox的内容

    (*// 标题:获取其他进程中ListBox和ComboBox的内容 说明:Window2000+Delphi6调试通过 设计:Zswang 支持:wjhu111@21cn.com 日期:2004-0 ...

  9. 利用 __FUNCTION__ 宏打印函数调用信息

    __FUNCTION__ 宏表示当前所在函数名: __FILE__ 宏表示当前所在文件路径: __LING__ 宏表示当前所在行: 利用对象离开函数时调用析构函数销毁的特点,打印出函数执行结束的信息 ...

  10. dubbo-admin管理平台搭建

    参考:http://blog.csdn.net/u013142781/article/details/50396621 一.前言 dubbo的使用,其实只需要有注册中心,消费者,提供者这三个就可以使用 ...