bzoj 2618: [Cqoi2006]凸多边形 [半平面交]
2618: [Cqoi2006]凸多边形
半平面交
注意一开始多边形边界不要太大...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define y1 y1z
using namespace std;
typedef long long ll;
const double eps = 1e-10, inf = 1e10;
const int N = 1005;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c=='-')f=-1; c=getchar();}
while(c >= '0' && c <= '9') {x=x*10+c-'0'; c=getchar();}
return x * f;
}
inline double _abs(double x) {return x < 0 ? -x : x;}
inline int sgn(double x) {return _abs(x) < eps ? 0 : (x < 0 ? -1 : 1);}
struct meow {
double x, y;
meow(double x = 0, double y = 0) : x(x), y(y) {}
bool operator <(const meow &r) const {return sgn(x - r.x) == 0 ? sgn(y - r.y) < 0 : sgn(x - r.x) < 0;}
void print() {printf("(%lf, %lf)\n", x, y);}
} ;
typedef meow Vector; typedef Vector Point;
meow operator + (meow a, meow b) {return meow(a.x + b.x, a.y + b.y);}
meow operator - (meow a, meow b) {return meow(a.x - b.x, a.y - b.y);}
meow operator * (meow a, double b) {return meow(a.x * b, a.y * b);}
meow operator / (meow a, double b) {return meow(a.x / b, a.y / b);}
double operator * (meow a, meow b) {return a.x * b.x + a.y * b.y;}
double operator ^ (meow a, meow b) {return a.x * b.y - a.y * b.x;}
struct Line {
Point s, t, v;
Line() {}
Line(Point s, Point t) : s(s), t(t) {v = t - s;}
} ;
bool on_left(Point a, Line l) {
return sgn(l.v ^ (a - l.s)) >= 0;
}
bool is_lsi(Line l1, Line l2) {
return sgn((l2.s - l1.s) ^ l1.v) != sgn((l2.t - l1.s) ^ l1.v);
}
Point lli(Line l1, Line l2) {
Point p = l1.s, q = l2.s; Vector u = l1.v, v = l2.v;
double k = ((q - p) ^ v) / (u ^ v);
return p + u * k;
}
void ini_polygon(Point *p, int &n) {
n = 0;
p[++n] = Point(-inf, -inf);
p[++n] = Point(inf, -inf);
p[++n] = Point(inf, inf);
p[++n] = Point(-inf, inf);
}
void cut_polygon(Point *p, int &n, Line l) {
Point c, d;
static Point t[N]; int tn = 0;
for(int i=1; i<=n; i++) {
c = p[i], d = p[i%n+1];
if(on_left(c, l)) t[++tn] = c;
if(is_lsi(l, Line(c, d))) t[++tn] = lli(l, Line(c, d));
}
n = tn;
for(int i=1; i<=tn; i++) p[i] = t[i];
}
double polygon_area(Point *p, int n) {
double s = 0;
for(int i=2; i<n; i++) s += (p[i] - p[1]) ^ (p[i+1] - p[1]);
return abs(s / 2);
}
int n, m, pn; Point a[N], p[N];
int main() {
freopen("in", "r", stdin);
n = read();
ini_polygon(p, pn);
for(int i=1; i<=n; i++) {
m = read();
for(int i=1; i<=m; i++) scanf("%lf %lf", &a[i].x, &a[i].y);
for(int i=1; i<=m; i++) cut_polygon(p, pn, Line(a[i], a[i%m+1]));
}
//for(int i=1; i<=pn; i++) p[i].print();
double ans = polygon_area(p, pn);
printf("%.3lf\n", ans);
}
bzoj 2618: [Cqoi2006]凸多边形 [半平面交]的更多相关文章
- 2018.07.04 BZOJ 2618 Cqoi2006凸多边形(半平面交)
2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec Memory Limit: 128 MB Description 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n ...
- 洛谷 P4196 [CQOI2006]凸多边形 (半平面交)
题目链接:P4196 [CQOI2006]凸多边形 题意 给定 \(n\) 个凸多边形,求它们相交的面积. 思路 半平面交 半平面交的模板题. 代码 #include <bits/stdc++. ...
- ●BZOJ 2618 [Cqoi2006]凸多边形
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2618 题解: 计算几何,半平面交. 给出一些凸包,求面积交. 把所有边都取出来,直接办平面交 ...
- 【BZOJ 2618】 2618: [Cqoi2006]凸多边形 (半平面交)
2618: [Cqoi2006]凸多边形 Description 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. Input 第一 ...
- bzoj 2618 2618: [Cqoi2006]凸多边形(半平面交)
2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 656 Solved: 340[Submit][Status] ...
- BZOJ - 2618 凸多边形 (半平面交)
题意:求n个凸多边形的交面积. 半平面交模板题. #include<bits/stdc++.h> using namespace std; typedef long long ll; ty ...
- bzoj 3190 [JLOI2013]赛车 半平面交+细节处理
题目大意 这里有一场赛车比赛正在进行,赛场上一共有N辆车,分别称为g1,g2--gn.赛道是一条无限长的直线.最初,gi位于距离起跑线前进ki的位置.比赛开始后,车辆gi将会以vi单位每秒的恒定速度行 ...
- bzoj 1038 瞭望塔 半平面交+分段函数
题目大意 给你一座山,山的形状在二维平面上为折线 给出\((x_1,y_1),(x_2,y_2)...(x_n,y_n)\)表示山的边界点或转折点 现在要在\([x_1,x_n]\)(闭区间)中选择一 ...
- 【BZOJ-2618】凸多边形 计算几何 + 半平面交 + 增量法 + 三角剖分
2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 959 Solved: 489[Submit][Status] ...
随机推荐
- MySQL数据库全备
#function:MYSQL自动全备 #version:1.0.0 #author:wangyanlin #date:2017/08/03 #---------------------------- ...
- CentOS 6.5 搭建 Zabbix
CentOS 6.5 搭建 Zabbix 说明: 操作系统:CentOS 6.5 IP地址:192.168.21.127 Web环境:Nginx+MySQL+PHP zabbix版本:Zabbix 2 ...
- JS验证两次输入密码是否相同
js中 <script>function check(){ with(document.all){if(input1.value!=input2.value){alert("fa ...
- 96、python version 3.6 required,which was not fount in the registry(python3.6安装scrapy)
在安装scrapy时遇到问题 环境:win10(64位), Python3.6(64位) 安装scrapy: 1.安装wheel(安装后,便支持通过wheel文件安装软件) pip3 install ...
- [国嵌笔记][019][Eclipse集成开发环境]
Eclipse集成开发环境的作用 可以编译程序,也可以对程序进行在线调试 集成开发环境 1.JLink连接开发板的JTAG 2.JLink连接PC的USB 3.eclipse软件 4.gdb serv ...
- HTTP协议----->连接管理
1. TCP连接 1.1 TCP为HTTP提供了一条可靠的比特传输管道. TCP(Transmission Control Protocol)----传输控制协议,是主机对主机层的传输控制协议,提 ...
- js定时器之setTimeout的使用
之前用过定时器,只不过用的不是很多,关于js定时器,一般而言我们很容易想到setInterval和setTimeout这两种. 刚开始学js定时器时,记住了setInterval,该方法一般用于每隔多 ...
- UE4 custom depth 自定义深度
用途1: 半透明材质中实现遮挡Mesh自己其他部分的效果. 不遮挡效果如下: 遮挡后效果如下: 实现方法: 深度信息是越远值越大,使用两个Mesh,一个正常渲染,另一个渲染到custom depth ...
- JAVA:创建类和对象
package duixiang; public class duixiang { /* * 类的实例化:创建对象 */ public static void main(String[] args) ...
- Jquery如何删除table里面checkbox选中的多个行
思路:遍历被选中的checkbox对象→根据选中项筛选出需要删除的行→删除行.实例说明如下: 1.HTML结构 <table id = "test_table"> &l ...