This article is made by Jason-Cow.
Welcome to reprint.
But please post the article's address.

题意,求半平面交,并且保证有解

poj2451

给张图边界(|x,y|<=1000,题目为1e4)

别问我为什么TLE

我当成多组处理没有判断文末符号,加上就!A!

直接上模板

 #include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define sqr(x) ((x)*(x))
#define RG register
#define op operator
#define IL inline
typedef double db;
typedef bool bl;
const db pi=acos(-1.0),eps=1e-;
struct D{
db x,y;
D(db x=0.0,db y=0.0):x(x),y(y){}
};
typedef D V;
bl operator<(D A,D B){return A.x<B.x||(A.x==B.x&&A.y<B.y);}
V operator+(V A,V B){return V(A.x+B.x,A.y+B.y);}
V operator-(V A,V B){return V(A.x-B.x,A.y-B.y);}
V operator*(V A,db N){return V(A.x*N,A.y*N);}
V operator/(V A,db N){return V(A.x/N,A.y/N);} db Ang(db x){return(x*180.0/pi);}
db Rad(db x){return(x*pi/180.0);}
V Rotate(V A,db a){return V(A.x*cos(a)-A.y*sin(a),A.x*sin(a)+A.y*cos(a));}
db Dis(D A,D B){return sqrt(sqr(A.x-B.x)+sqr(A.y-B.y));}
db Cross(V A,V B){return A.x*B.y-A.y*B.x;} db Area(D*R,int n){
db S=0.0;
for(int i=;i<n;i++)S+=Cross(R[i]-R[],R[i+]-R[]);
return S/;
} db Length(D*R,int n){
db C=0.0;
for(int i=;i<=n;i++)C+=Dis(R[i],R[i-]);
return C+Dis(R[n],R[]);
} struct L{
D P,v;
db a;
L(){}
L(D P,V v):P(P),v(v){a=atan2(v.y,v.x);}
bool operator<(const L x)const{return a<x.a;}
}; D Intersect(L a,L b){
V u=a.P-b.P;
return a.P+a.v*(Cross(b.v,u)/Cross(a.v,b.v));
} bool Left(L l,D A){
return Cross(l.v,A-l.P)>;
} int HPI(L*l,int n,D*ans){
int head,tail,m=;
D*P=new D[n];L*q=new L[n];
sort(l+,l+n+),q[head=tail=]=l[];
for(int i=;i<=n;i++){
while(head<tail && !Left(l[i],P[tail-]))tail--;
while(head<tail && !Left(l[i],P[head])) head++;
q[++tail]=l[i];
if(fabs(Cross(q[tail].v,q[tail-].v))<eps){
tail--;
if(Left(q[tail],l[i].P))q[tail]=l[i];
}
if(head<tail)P[tail-]=Intersect(q[tail-],q[tail]);
}
while(head<tail && !Left(q[head],P[tail-]))tail--;
if(tail-head<=)return ;
P[tail]=Intersect(q[tail],q[head]);
for(int i=head;i<=tail;i++)ans[++m]=P[i];
return m;
} const int maxn=2e4+;
L l[maxn];D A[maxn];
int main(){
D LU(,1e4),LD(,),RD(1e4,),RU(1e4,1e4);
for(int n;scanf("%d",&n)!=EOF;){
for(int i=;i<=n;i++){
db a,b,c,d;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
D A(a,b),B(c,d);
l[i]=L(A,B-A);
}
l[++n]=L(LU,V(,-));
l[++n]=L(LD,V(,));
l[++n]=L(RD,V(,));
l[++n]=L(RU,V(-,));
int m=HPI(l,n,A);
printf("%.1lf\n",Area(A,m));
}
return ;
}

计算几何-poj2451-HPI的更多相关文章

  1. 计算几何-BZOJ2618-凸包的交-HPI

    This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. bzoj2618 ...

  2. 计算几何-HPI

    This article is made by Jason-Cow.Welcome to reprint.But please post the article's address.   在线笛卡尔坐 ...

  3. ACM/ICPC 之 计算几何入门-叉积-to left test(POJ2318-POJ2398)

    POJ2318 本题需要运用to left test不断判断点处于哪个分区,并统计分区的点个数(保证点不在边界和界外),用来做叉积入门题很合适 //计算几何-叉积入门题 //Time:157Ms Me ...

  4. HDU 2202 计算几何

    最大三角形 Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. ACM 计算几何中的精度问题(转)

    http://www.cnblogs.com/acsmile/archive/2011/05/09/2040918.html 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模 ...

  6. hdu 2393:Higher Math(计算几何,水题)

    Higher Math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)

    Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a b ...

  8. [知识点]计算几何I——基础知识与多边形面积

    // 此博文为迁移而来,写于2015年4月9日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102vxaq.html 1.前言 ...

  9. POJ 1106 Transmitters(计算几何)

    题目链接 切计算几何,感觉计算几何的算法还不熟.此题,枚举线段和圆点的直线,平分一个圆 #include <iostream> #include <cstring> #incl ...

随机推荐

  1. vue制作滚动条幅-跑马灯效果实例代码

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. SVM-支持向量机(一)线性SVM分类

    SVM-支持向量机 SVM(Support Vector Machine)-支持向量机,是一个功能非常强大的机器学习模型,可以处理线性与非线性的分类.回归,甚至是异常检测.它也是机器学习中非常热门的算 ...

  3. LED And Incandescent, Who Is Suitable For Holiday Lighting?

    Fast-fire advantages of LED lighting: Eco-friendly-LEDs are not made of toxic chemicals, such as mer ...

  4. yii消息提示扩展

    //安装 composer.phar require --prefer-dist yiister/yii2-gentelella "~1.0" //消息存入 Yii::$app-& ...

  5. C++-POJ2234-Matches Game[Nim][SG函数]

    #include <set> #include <map> #include <cmath> #include <queue> #include < ...

  6. 动态规划 ---- 最长不下降子序列(Longest Increasing Sequence, LIS)

    分析: 完整 代码: // 最长不下降子序列 #include <stdio.h> #include <algorithm> using namespace std; ; in ...

  7. Suggestions On Setting LED Holiday Light

    We all like the cheerful glow of holiday lights, so the process goes seamless from start to finish. ...

  8. IIS7.5 HTTP 错误 500 调用loadlibraryex失败的解决方法

    在IIS7.5打开网页的时候,提示: HTTP 错误 500.0 - Internal Server Error 调用 LoadLibraryEx 失败,在 ISAPI 筛选器 C:\Windows\ ...

  9. 一次 utf-8 bom引起的问题

    同事代码新增加了功能,推到服务器上,意外导致登录失败,回退到之前的版本上,可以正常使用. 这次只上传了 route.php 文件,系统登录失败. 随后使用kdiff3对比了两版本的route.php文 ...

  10. path is not a working copy directory

    svn: 'G:\chengXu\2017_Year\JFW\Easy7\WebRoot' is not a working copy directory 解决方法: (1)原因:eclipse把sr ...