简单几何(向量旋转+凸包+多边形面积) UVA 10652 Board Wrapping
题意:告诉若干个矩形的信息,问他们在凸多边形中所占的面积比例
分析:训练指南P272,矩形面积长*宽,只要计算出所有的点,用凸包后再求多边形面积。已知矩形的中心,向量在原点参考点再旋转,角度要转换成弧度制。
/************************************************
* Author :Running_Time
* Created Time :2015/11/10 星期二 10:34:43
* File Name :UVA_10652.cpp
************************************************/ #include <bits/stdc++.h>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos (-1.0);
int dcmp(double x) {
if (fabs (x) < EPS) return 0;
else return x < 0 ? -1 : 1;
}
struct Point {
double x, y;
Point () {}
Point (double x, double y) : x (x), y (y) {}
Point operator - (const Point &r) const { //向量减法
return Point (x - r.x, y - r.y);
}
Point operator * (double p) const { //向量乘以标量
return Point (x * p, y * p);
}
Point operator / (double p) const { //向量除以标量
return Point (x / p, y / p);
}
Point operator + (const Point &r) const {
return Point (x + r.x, y + r.y);
}
bool operator < (const Point &r) const {
return x < r.x || (x == r.x && y < r.y);
}
bool operator == (const Point &r) const {
return dcmp (x - r.x) == 0 && dcmp (y - r.y) == 0;
}
};
typedef Point Vector;
double dot(Vector A, Vector B) { //向量点积
return 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 area_poly(vector<Point> ps) {
double ret = 0;
for (int i=1; i<ps.size ()-1; ++i) {
ret += fabs (cross (ps[i] - ps[0], ps[i+1] - ps[0])) / 2;
}
return ret;
}
vector<Point> convex_hull(vector<Point> ps) {
sort (ps.begin (), ps.end ());
ps.erase (unique (ps.begin (), ps.end ()), ps.end ());
int n = ps.size (), k = 0;
vector<Point> qs (n * 2);
for (int i=0; i<n; ++i) {
while (k > 1 && cross (qs[k-1] - qs[k-2], ps[i] - qs[k-2]) <= 0) k--;
qs[k++] = ps[i];
}
for (int t=k, i=n-2; i>=0; --i) {
while (k > t && cross (qs[k-1] - qs[k-2], ps[i] - qs[k-2]) <= 0) k--;
qs[k++] = ps[i];
}
qs.resize (k - 1);
return qs;
} int main(void) {
int T; scanf ("%d", &T);
while (T--) {
int n; scanf ("%d", &n);
vector<Point> ps;
double area1 = 0;
double x, y, w, h, r;
for (int i=0; i<n; ++i) {
scanf ("%lf%lf%lf%lf%lf", &x, &y, &w, &h, &r);
Point a = Point (x, y);
area1 += w * h;
r = -r / 180 * PI;
ps.push_back (a + rotate (Vector (-w/2, -h/2), r));
ps.push_back (a + rotate (Vector (w/2, -h/2), r));
ps.push_back (a + rotate (Vector (w/2, h/2), r));
ps.push_back (a + rotate (Vector (-w/2, h/2), r));
}
vector<Point> qs = convex_hull (ps);
printf ("%.1f %%\n", 100 * area1 / area_poly (qs));
} //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0;
}
简单几何(向量旋转+凸包+多边形面积) UVA 10652 Board Wrapping的更多相关文章
- UVA 10652 Board Wrapping 计算几何
多边形凸包.. .. Board Wrapping Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu ...
- Uva 10652 Board Wrapping(计算几何之凸包+点旋转)
题目大意:给出平面上许多矩形的中心点和倾斜角度,计算这些矩形面积占这个矩形点形成的最大凸包的面积比. 算法:GRAHAM,ANDREW. 题目非常的简单,就是裸的凸包 + 点旋转.这题自己不会的地方就 ...
- UVA 10652 Board Wrapping(二维凸包)
传送门 刘汝佳<算法竞赛入门经典>P272例题6包装木板 题意:有n块矩形木板,你的任务是用一个面积尽量小的凸多边形把它们抱起来,并计算出木板占整个包装面积的百分比. 输入:t组数据,每组 ...
- UVA 10652 Board Wrapping(凸包)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32286 [思路] 凸包 根据角度与中心点求出长方形所有点来,然后就 ...
- 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
主要是凸包的应用: #include <cstdio> #include <cmath> #include <cstring> #include <algor ...
- poj3348 Cows 凸包+多边形面积 水题
/* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...
随机推荐
- 新浪微博的XSS漏洞攻击过程详解
今天晚上(2011年6月28日),新浪微博出现了一次比较大的XSS攻击事件.大量用户自动发送诸如:“郭美美事件的一些未注意到的细节”,“建 党大业中穿帮的地方”,“让女人心动的100句诗歌”,“3D肉 ...
- HNU 12845 Ballot Analyzing Device
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12845&courseid=270 解题报告:有m个认给 ...
- 高流量站点NGINX与PHP-fpm配置优化
导读 使用Nginx搭配PHP已有7年的经历,这份经历让我们学会如何为高流量站点优化NGINX和PHP-fpm配置. 以下正是这方面的一些提示和建议: 1. 将TCP切换为UNIX域套接字 1. 将T ...
- git clone报错
(文章是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) Could not chdir to home directory /home/wangzheng: ...
- Windows/Centos安装GO语言环境
转载:http://www.haiyun.me/archives/1009.html Centos下使用epel源安装: 1 yum install golang Centos/Linux下源码安装g ...
- 对比WDCP面板与AMH面板的区别与选择
转载: http://www.laozuo.org/2760.html | 老左博客 随着VPS主机的性价比提高(其实就是降价)我们很多站长会越来越多的选择使用VPS搭建网站或者运营一些项目,相比较而 ...
- HDU3344(小广搜+小暴力
Kakuro Extension Extension Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- MySql 插入数据中文乱码
在数据库连接URL后加上characterEncoding=UTF-8 driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/ssm ...
- 在Java中>、>>、>>>三者的区别
Java,是由Sun Microsystems公司于1995年5月推出的Java程序设计语言和Java平台的总称.用Java实现的HotJava浏览器(支持Java applet)显示了Java的魅力 ...
- jquery unbind bind
$(selector).unbind(); --unbind() 方法会删除指定元素的所有事件处理程序 $(selector).unbind("click"); --unbind( ...