【CSU1812】三角形和矩形 【半平面交】
检验半平面交的板子。
#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】三角形和矩形 【半平面交】的更多相关文章
- 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 ...
- BZOJ3199 SDOI2013 逃考 半平面交、最短路
传送门 如果我们对于每一个点能找到与其相邻的点(即不经过其他点监视范围能够直接到达其监视范围的点)和是否直接到达边界,就可以直接BFS求最短路求出答案. 所以当前最重要的问题是如何找到对于每一个点相邻 ...
- Luogu3297 SDOI2013逃考(半平面交+最短路)
把每个人的监视范围看成点,相邻的两个监视范围连边,那么跑一遍最短路就可以了(事实上边权都为1可以直接bfs).显然存在最优路线没有某个时刻同时被多于两人监视,要到达另一个区域的话完全可以经过分界线而不 ...
- HDU - 3982:Harry Potter and J.K.Rowling(半平面交+圆与多边形求交)(WA ing)
pro:给定一枚蛋糕,蛋糕上某个位置有个草莓,寿星在上面切了N刀,最后寿星会吃含有草莓的那一块蛋糕,问他的蛋糕占总蛋糕的面积比. sol:显然需要半平面交求含有蛋糕的那一块,然后有圆弧,不太方便求交. ...
- 洛谷P4250 [SCOI2015]小凸想跑步(半平面交)
题面 传送门 题解 设\(p\)点坐标为\(x_p,y_p\),那么根据叉积可以算出它与\((i,i+1)\)构成的三角形的面积 为了保证\(p\)与\((0,1)\)构成的面积最小,就相当于它比其它 ...
- 再来一道测半平面交模板题 Poj1279 Art Gallery
地址:http://poj.org/problem?id=1279 题目: Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Su ...
- 三道半平面交测模板题 Poj1474 Poj 3335 Poj 3130
求半平面交的算法是zzy大神的排序增量法. ///Poj 1474 #include <cmath> #include <algorithm> #include <cst ...
- POJ 1279 Art Gallery 半平面交/多边形求核
http://poj.org/problem?id=1279 顺时针给你一个多边形...求能看到所有点的面积...用半平面对所有边取交即可,模版题 这里的半平面交是O(n^2)的算法...比较逗比.. ...
- 计算几何板子题【2019牛客国庆集训派对day7——三角形和矩形】【多边形相交的面积】
链接:https://ac.nowcoder.com/acm/contest/1112/J来源:牛客网 题目描述 Bobo 有一个三角形和一个矩形,他想求他们交的面积. 具体地,三角形和矩形由 8 个 ...
随机推荐
- You and Your Research(Chinese)
转自:http://lyxh-2003.iteye.com/blog/434014 这是大科学家Richard Hamming的著名讲演,于1986年在贝尔通讯研究中心给200多名Bellcore的科 ...
- Nginx下TIME_WAIT过多的调优
查看Nginx并发状态 #netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' TIME_WAIT 1259SYN_ ...
- win commands
wmic process where name="explorer.exe" delete 我想你问得应该是运行命令吧!我查了,没有,你自己参考一下:Windows常用命令集 wi ...
- connect to https://dl-ssl.google.com refused
这个可能是网络问题,国内连google服务器经常连不上. 尝试用下面办法试下: 1.上图SDK Manager 的 Tools ->Options打开SDK Manager的Settings, ...
- OceanBase架构(二)
http://www.cnblogs.com/LiJianBlog/p/4779990.html OceanBase架构浅析(二) 单点性能 OceanBase架构的优势在于既支持跨行跨表事务,又 ...
- 物理主机win 7系统迁移至VMware ESXI服务器
一.实验环境如下图所示: 二.实验要求(如上图所示) 通过 计算机B (IP:10.8.9.18) 将 计算机A (IP:10.8.9.155) 迁移到 服务器(IP:10.8.9.161) 三.实 ...
- 关键字static/const的作用
static关键字的作用:(1)设置变量的存储域,函数体内static变量的作用范围为该函数体,不同于auto变量,该变量的内存只被分配一次,因此其值在下次调用时仍维持上次的值:(2)限制变量的作用域 ...
- ubuntu安装eclipse配置jdk环境
$ sudo mkdir /usr/local/java //在此目录下新建一个文件夹java $ sudo mv 下载/jdk-8u111-linux-i586.tar.gz /usr/local/ ...
- struts action和jsp之间的传值
一.jsp对Action传值 提交表单即可,Action的属性必须和表单的标签名字相同 二.Action对jsp传值: (1)利用session,(个人推荐) action中ActionContext ...
- U盘文件偷窃程序
// Drives.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "windows.h" #incl ...