【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 个 ...
随机推荐
- 使用NPOI将TABLE内容导出到EXCEL
项目中需要将页面中的table内容导出到EXCEL,在用了几种方法后发现NPO是最快&最好的 需要应用 NPOI.dll 还有个Ionic.Zip.dll不知道有用没,没去研究,两个DLL都放 ...
- yii框架分页
- ng-bind-html 的原素没有高度
angularjs里绑定html元素,在页面的div里使用ng-bind-html <!-- html--> <div class="info" ng-bind- ...
- RML-怎样的语句会被归纳为同一类型(Unique Batches)
我们知道使用RML工具分析跟踪数据(.TRC),其中的"Unique Batches",就是一个关于Batch级别的报表,Batch级别的报表针对的是存储过程或是一个TSQL Ba ...
- IBM服务器诊断面板
IBM服务器一般会有一个服务器操作员信息面板(诊断面板),服务器一般的硬件故障都会在诊断面板上提示,但这些提示可能只是一个大概的诊断故障,有助于系统管理员更好的维护. 一.IBM X3650 M3诊断 ...
- 产生0-9 A-Z a-z
>题目要求: >>产生26个大写字母 >>产生26个小写字母 >>产生0-9这10个阿拉伯数字 >程序实现: package cn.fury.test; ...
- JS倒计时——天时分秒
HTML代码: <div id="times_wrap" class="time_num"> 距离结束时间: <div cl ...
- Web动画API教程2:AnimationPlayer和Timeline
本文转载: Web动画API教程2:AnimationPlayer和Timeline
- .NET开发实战1-军队未出,粮草先行。
马上期末考试了,会想起这个学习的自己.一直都在一个人搞java的研究,C#课也没怎么去上.所以在这里想弥补一下自己没去上课的原因,也希望老师能够理解这个还在迷茫的我. 正所谓,军队未出粮草先行,所以我 ...
- 函数nvl 和decode
decode(nvl(kkc.category, 'one'),'one','普通','two','精品','three','行业','four','白金')