【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 个 ...
随机推荐
- JSTL标签出错:<c:forEach var="book" items="${requestScope.books}" varStatus="status">
今天在运行书里的JSTL标签代码的时候出错,总结一下: 问题1.The JSP specification requires that an attribute name is preceded by ...
- hgrjhgkjh
#include<stdio.h> int step[5]={13,5,1,4,11}; int sum; int min=999; void ji() { int i; int j; ...
- XAMPP PHP redis 扩展
1.php增加redis扩展 echo phpinfo();exit;查看php 版本以及 vc运行库 可知 X86 MSVC11 PHP5.6 首先把对应版本的php_redis.dll 和 ...
- [LeetCode]题解(python):114 Flatten Binary Tree to Linked List
题目来源 https://leetcode.com/problems/flatten-binary-tree-to-linked-list/ Given a binary tree, flatten ...
- NSString(或者说是UILabel)加入 “行间距” 之后的 “高度”计算
一.首先,写一个工具类(NSString的分类,增加两个功能,计算高度宽度) #import "NSString+Extension.h" @implementation NSSt ...
- substr mb_substr mbstrct 的用法区别
1.substr遇到中文会出问题,用于截取英文字符 2.mb_substr() 按字符截取字符串,需要开启php_mbstring.dll <?php echo mb_substr(, , 'u ...
- 盒模型中--border
三要素:宽border-width,形状border-style,颜色border-color <style> div{ width:300px; height:300px; backgr ...
- JAVASE02-Unit02: 正则表达式 、 Object 、 包装类
正则表达式 . Object . 包装类 字符串支持正则表达式的方法一: package day02; /** * 字符串支持正则表达式的方法一: * boolean matches(String r ...
- mongoose index
1. 当应用程序启动时,Mongoose会自动为模式中的每个定义的索引调用ensureIndex. 虽然很好用于开发,但建议在生产中禁用此行为,因为索引创建可能会导致显着的性能影响. 通过将模式的au ...
- Oracle的日期时间范围查询
Oracle日期时间范围查询 Sql代码 /* 日期时间范围查询 */ ---------- 创建日期时间测试表-------------------------------------------- ...