計算幾何 poj2451 HPI

2022-05-13 18:09:21 字數 2108 閱讀 1626

this article is made byjason-cow.

welcome to reprint.

but please post the article's address.

題意,求半平面交,並且保證有解

poj2451

給張圖邊界(|x,y|<=1000,題目為1e4)

別問我為什麼tle

我當成多組處理沒有判斷文末符號,加上就!a!

直接上模板

1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 

11using

namespace

std;

12#define sqr(x) ((x)*(x))

13#define rg register

14#define op operator

15#define il inline

16 typedef double

db;17 typedef bool

bl;18

const db pi=acos(-1.0),eps=1e-10;19

structd22

};23

typedef d v;

24 bl operator

25 v operator+(v a,v b)

26 v operator-(v a,v b)

27 v operator*(v a,db n)

28 v operator/(v a,db n)

2930 db ang(db x)

31 db rad(db x)

32 v rotate(v a,db a)

33 db dis(d a,d b)

34 db cross(v a,v b)

3536 db area(d*r,int

n)41

42 db length(d*r,int

n)47

48struct

l52 l(d p,v v):p(p),v(v)

53bool

operator

54};

5556

d intersect(l a,l b)

6061

bool

left(l l,d a)

6465

int hpi(l*l,int n,d*ans)

77if(head1]=intersect(q[tail-1

],q[tail]);78}

79while(head1]))tail--;

80if(tail-head<=1)return0;

81 p[tail]=intersect(q[tail],q[head]);

82for(int i=head;i<=tail;i++)ans[++m]=p[i];

83return

m;84}85

86const

int maxn=2e4+10;87

l l[maxn];d a[maxn];

88int

main()

97 l[++n]=l(lu,v(0,-1

));98 l[++n]=l(ld,v(1,0

));99 l[++n]=l(rd,v(0,1

));100 l[++n]=l(ru,v(-1,0

));101

int m=hpi(l,n,a);

102 printf("

%.1lf\n

",area(a,m));

103}

104return0;

105 }

poj1696 計算幾何

運用叉積判斷是否是逆時針,因為同一直線上也行,所以有n個植物就可以吃掉n個植物 include include include include include define dist a,b sqrt 1.0 a.x b.x a.x b.x 1.0 a.y b.y a.y b.y define cr...

poj1106 計算幾何

求在可以旋轉的給定圓心和半徑的半圓中最多點的個數 include include include include include define dist a,b sqrt 1.0 a.x b.x a.x b.x 1.0 a.y b.y a.y b.y define cross a,b,c 1.0 b...

POJ 1106 計算幾何

解法 通過列舉每乙個點,然後判斷這個點的左邊和右邊分別有多少個點,然後統計乙個最大值就好了 在判斷的時候用斜率來判斷比較好 斜率大於k的一定在直線的左邊,反之就在左邊 include include define eps 1e 8 struct point point p 1005 point s ...