检验半平面交的板子。

 #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. principal-component-analysis

    http://support.minitab.com/en-us/minitab/17/topic-library/modeling-statistics/multivariate/principal ...

  2. iOS CAShapeLayer记录

    基本知识 看看官方说明: /* The shape layer draws a cubic Bezier spline in its coordinate space. * * The spline ...

  3. 转载 Servlet3.0中使用注解配置Servle

    转载地址:http://www.108js.com/article/article10/a0021.html?id=1496 开发Servlet3的程序需要一定的环境支持.Servlet3是Java ...

  4. MVC控制器常用方法返回类型

    控制器的常用方法 using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...

  5. fiddler note

    一晚上终于找到对的东西,作者很专业,这里作为笔记,想学习好东西还是到作者那里^_^ ---------------------------------------------------------- ...

  6. 厦门BRT 硬币型非接触式IC卡分析

    前几天去厦门玩顺便多买了一张BRT的票 也就是如图所示的这种硬币型非接触式IC卡 回来之后用Proxmark3分析了卡内数据得到如下16进制dump内容 UID.发卡日期时间. 最近好懒 懒得写了 有 ...

  7. 解决redmine写操作很慢的问题

    以前刚开始时用redmine是直接使用它的webrick服务器来运行的,后来为了提高性能,采用nginx+passenger的方式来驱动redmine,访问速度快了不少,但是在新建问题或更新问题时变得 ...

  8. :enabled 匹配所有可用元素

    描述: 查找所有可用的input元素 HTML 代码: <form> <input name="email" disabled="disabled&qu ...

  9. 编译boost

    参数意义: --build-dir:  编译的临时文件会放在builddir里(这样比较好管理,编译完就可以把它删除了) --stagedir:  存放编译后库文件的路径,默认是stage --bui ...

  10. Linux之netstat命令详解

    简介 Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Member ...