检验半平面交的板子。

 #include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define gg puts("gg");
#define ll long long
const double pi = acos(-);
const double eps = 1e-;
int dcmp(double x){
if(fabs(x) < eps) return ;
return x > ? : -;
}
struct Point{
double x, y;
Point(double x = , double y = ):x(x), y(y){}
Point operator +(const Point& a){ return Point(x+a.x, y+a.y);}
Point operator -(const Point& a){ return Point(x-a.x, y-a.y);}
Point operator *(const Point& a){ return Point(x*a.x, y*a.y);}
Point operator *(const double a){ return Point(x*a, y*a); }
};
struct Line{
Point p, v; double a;
Line(){}
Line(Point p, Point v):p(p), v(v){ a = atan2(v.y, v.x);}
bool operator <(const Line& b) const{
return a < b.a;
}
}; double Cross(const Point& a, const Point& b){
return a.x*b.y-a.y*b.x;
}
bool Onleft(Line L, Point P){
return Cross(L.v, P-L.p) > ;
}
Point GetIntersection(Line a, Line b){
Point u = a.p-b.p;
double t = Cross(b.v, u)/Cross(a.v, b.v);
return a.p+a.v*t;
}
int Hpi(Line* L, int n, Point* poly, Point* p, Line* q){
sort(L, L+n);
int first, last;
q[first = last = ] = L[];
for(int i = ; i < n; i++){
while(first < last&&!Onleft(L[i], p[last-])) last--;
while(first < last&&!Onleft(L[i], p[first])) first++;
q[++last] = L[i];
if(fabs(Cross(q[last].v, q[last-].v)) < eps){
last--;
if(Onleft(q[last], L[i].p)) q[last] = L[i];
}
if(first < last) p[last-] = GetIntersection(q[last-], q[last]);
}
while(first < last&&!Onleft(q[first], p[last-])) last--;
if(last-first <= ) return ;
p[last] = GetIntersection(q[last], q[first]); int m = ;
for(int i = first; i <= last; i++)
poly[m++] = p[i];
return m;
}
double PolygonArea(Point* p, int n){
double ans = ;
for(int i = ; i < n-; i++)
ans += Cross(p[i]-p[], p[i+]-p[]);
return ans/2.0;
} Line L[], q[];
Point p[], poly[]; double x[], y[];
int main(){
while(~scanf("%lf%lf", x+, y+)){
for(int i = ; i <= ; i++)
scanf("%lf%lf", x+i, y+i);
p[] = Point(x[], y[]);
p[] = Point(x[], y[]);
p[] = Point(x[], y[]);
if(Onleft(Line(p[], p[]-p[]), p[]))
L[] = Line(p[], p[]-p[]);
else
L[] = Line(p[], p[]-p[]); if(Onleft(Line(p[], p[]-p[]), p[]))
L[] = Line(p[], p[]-p[]);
else
L[] = Line(p[], p[]-p[]); if(Onleft(Line(p[], p[]-p[]), p[]))
L[] = Line(p[], p[]-p[]);
else
L[] = Line(p[], p[]-p[]);
///////////////////////////////////////
L[] = Line(Point(x[], y[]), Point(, ));
L[] = Line(Point(x[], y[]), Point(, ));
L[] = Line(Point(x[], y[]), Point(-, ));
L[] = Line(Point(x[], y[]), Point(, -));
int tot = Hpi(L, , poly, p, q);
if(tot == ) printf("%.8f\n", 0.0);
else
printf("%.8f\n", PolygonArea(poly, tot));
}
return ;
}

【CSU1812】三角形和矩形 【半平面交】的更多相关文章

  1. Harry Potter and J.K.Rowling(半平面交+圆和矩形交)

    Harry Potter and J.K.Rowling http://acm.hdu.edu.cn/showproblem.php?pid=3982 Time Limit: 2000/1000 MS ...

  2. BZOJ3199 SDOI2013 逃考 半平面交、最短路

    传送门 如果我们对于每一个点能找到与其相邻的点(即不经过其他点监视范围能够直接到达其监视范围的点)和是否直接到达边界,就可以直接BFS求最短路求出答案. 所以当前最重要的问题是如何找到对于每一个点相邻 ...

  3. Luogu3297 SDOI2013逃考(半平面交+最短路)

    把每个人的监视范围看成点,相邻的两个监视范围连边,那么跑一遍最短路就可以了(事实上边权都为1可以直接bfs).显然存在最优路线没有某个时刻同时被多于两人监视,要到达另一个区域的话完全可以经过分界线而不 ...

  4. HDU - 3982:Harry Potter and J.K.Rowling(半平面交+圆与多边形求交)(WA ing)

    pro:给定一枚蛋糕,蛋糕上某个位置有个草莓,寿星在上面切了N刀,最后寿星会吃含有草莓的那一块蛋糕,问他的蛋糕占总蛋糕的面积比. sol:显然需要半平面交求含有蛋糕的那一块,然后有圆弧,不太方便求交. ...

  5. 洛谷P4250 [SCOI2015]小凸想跑步(半平面交)

    题面 传送门 题解 设\(p\)点坐标为\(x_p,y_p\),那么根据叉积可以算出它与\((i,i+1)\)构成的三角形的面积 为了保证\(p\)与\((0,1)\)构成的面积最小,就相当于它比其它 ...

  6. 再来一道测半平面交模板题 Poj1279 Art Gallery

    地址:http://poj.org/problem?id=1279 题目: Art Gallery Time Limit: 1000MS   Memory Limit: 10000K Total Su ...

  7. 三道半平面交测模板题 Poj1474 Poj 3335 Poj 3130

    求半平面交的算法是zzy大神的排序增量法. ///Poj 1474 #include <cmath> #include <algorithm> #include <cst ...

  8. POJ 1279 Art Gallery 半平面交/多边形求核

    http://poj.org/problem?id=1279 顺时针给你一个多边形...求能看到所有点的面积...用半平面对所有边取交即可,模版题 这里的半平面交是O(n^2)的算法...比较逗比.. ...

  9. 计算几何板子题【2019牛客国庆集训派对day7——三角形和矩形】【多边形相交的面积】

    链接:https://ac.nowcoder.com/acm/contest/1112/J来源:牛客网 题目描述 Bobo 有一个三角形和一个矩形,他想求他们交的面积. 具体地,三角形和矩形由 8 个 ...

随机推荐

  1. ios计算内容的高度 (含7.0前及以后的版本的用法)

    + (CGFloat)heightForContent:(MyMsgTextModel *)content withWidth:(CGFloat)width { CGSize contentSize; ...

  2. 我的PhoneGap安装配置经历

    一.PhoneGap简介 PhoneGap是一个用基于HTML,CSS和JavaScript的,创建移动跨平台移动应用程序的快速开发平台.它使开发者能够利用 iPhone,Android,Palm,S ...

  3. centos7 开机画面定制

    安装包 yum install plymouth-plugin-script 设置开机启动画面 mkdir /usr/share/plymouth/themes/tup 创建主题目录 cp /root ...

  4. 去掉comments

    三种comments: /* Test program */ int main() { // variable declaration int a, b, c; /* This is a test m ...

  5. php闭包实现函数的自调用,也是递归

    php的闭包可能不常用,但是在某些场合之下还是可以考虑用php的闭包来实现某些功能的,比如递归,这里讲一下用php的闭包实现递归 //php闭包实现函数的自调用,也就是实现递归 function cl ...

  6. Python开发【第七章】:Python异常处理

    一.异常处理 1.异常基础 在编程过程中为了增加友好性,在程序出现bug时一般不会将错误信息显示给用户,而是现实一个提示的页面,通俗来说就是不让用户看见大黄页!!! #异常处理 list = [&qu ...

  7. ionic下拉加载自动触发

    ionic提供的下拉加载,是要滑动去下拉加载,没有提供api自动触发下拉加载,比如刚进页面,或者切换tab时想触发一次下拉加载. 添加如下service: angular.module('YourAp ...

  8. SEO之HTML优化:让你的网站HTML代码更符合SEO规范

    摘要HTML优化是网站内部优化的重点,可能对SEO新手来说,容易忽略.符合搜索引擎习惯的HTML代码是极利于SEO的,可以让你的网站获得更好的搜索引擎排名.如何制作一个标准的HTML网页,如何做HTM ...

  9. [Android Tips] 9. framework notification layout font size

    android 4.4 framework notification layout 相关字体大小 * title: notification_title_text_size: 18dp * conte ...

  10. SQLite Expert 删除表数据并重置自动增长列

    用下面的语句肯定是行不通的,语句不支持 truncate table t_Records 方法:1.删除表数据 2.重置自动增长列 where name='t_Records' /*name :是表名 ...