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] ...
随机推荐
- 2017ecjtu-summer training #6 Gym 100952D
D. Time to go back time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 从parcel.js打包出错,到拥抱nvm
去年年底发布的parcel.js在年底可谓是火了一把,短短一个多月的时间在GitHub热门排行榜上名列前茅.因其几乎零配置的易用性,相比Webpack的复杂配置收获了大量关注及好评,甚至有人预言未来大 ...
- 从零开始学习前端开发 — 11、CSS3选择器
一.基本选择器 1.* 通配符(通用选择器) 2.id选择器 3.class选择器(类选择器) 4.标签选择器(元素选择符) 5.群组选择器 (选择符1,选择符2{...}) 二.层次选择器(关系选择 ...
- 十二个 ASP.NET Core 例子——IOC
目录 简单介绍 core自带IOC的实现解释 1.简单介绍 (个人理解) 是什么:IOC是一种设计原则,而非设计模式,是对流程控制,当你注入你需要的定制化类时,流程就确定了 怎么用:和IOC容器说你这 ...
- 无格式转换php
// 无格式转换function ClearHtml($content,$allowtags='') { mb_regex_encoding('UTF-8'); //replace MS specia ...
- [SinGuLaRiTy] 复习模板-高精度模板
[SinGuLaRiTy-1042] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 结构体封装 //高精度运算 注意%I64d与%lld # ...
- href
<a href="#"></a>点击浏览器会跳转地址栏加了#:<a href=""></a>点击会打开当前网页所 ...
- Angular4+路由
路由的作用就是(导航):会加载与请求路由相关联的组件,并获取特定路由的相关数据,这允许我们通过控制不同的路由,获取不同的数据,从而渲染不同的页面: 几种常见的路由配置: Angular路由器是一个可选 ...
- Insert Sort Singly List
对单链表插入排序,给出个单链表的head节点:返回排完序的head节点: 首先数据结构中习惯了以数组为参数排序,瞬间想到是遍历单链表存入arraylist中,再进行insert sort,(O(n** ...
- start tomcat with debugging mode
For this, you must run your application in debug mode, which requires below parameters. -Xdebug -Xru ...