[BZOJ2618] CQOI2006 Convex polygon | Scan Line __ Computational geometry

Source: Internet
Author: User
Tags cmath

The area of the convex polygon and seems to have a lot of way, the Net has O (N^2LOGN) algorithm, the nest will only O (N^3LOGN) scan line violence (seems to be able to do O (n^3) is to solve. The endpoints of all triangles and intersections are sorted together so that all the images are divided into several intervals, each area of which is a number of trapezoidal (triangles can also be used as a trapezoid), and then the total length of the median line of the cumulative area on the line. To find the length of the median line with X=mid to get all the points, and then arrange a sequence, recorded through a point of intersection is into a triangle or a triangle, when 0 to add a length, or very good writing. Not how to tune on, but the answer to-eps can live.

#include <cstdio> #include <iostream> #include <cmath> #include <algorithm> #include <cstdio > #include <cmath> #include <iostream> #include <algorithm> #include <memory.h> #define H1 que [Head] #define H2 que[head+1] #define T1 que[tail] #define T2 QUE[TAIL-1] #define N 510 #define EPS 1e-8 using namespace s
td
	struct point{double x,y;
Point () {} point (double x,double y): x (x), Y (y) {}}p[n],p1,p2,h;
	struct line{point p,v;
Double angle;
}a[n],que[n];
int I,j,head,tail,cnt,n,m,tot;
Double ans; Point operator-(point A,point b) {return point (A.X-B.X,A.Y-B.Y);} point operator+ (point A,point b) {return point (a.x+b.x,
A.Y+B.Y);}
Point operator* (Double k,point a) {return point (K*A.X,K*A.Y);} double operator* (point A,point b) {return a.x*b.y-a.y*b.x;} BOOL CMP (line A,line b) {if (A.angle!=b.angle) return a.angle<b.angle;else return b.v* (A.P-B.P) >0;} point Cross (l
	INE A,line b) {point t=a.p+a.v; Double k1= (A.P-B.P) *b.v,k2=b.v* (T-B.P), k=k1/(K1+K2);
return K*A.V+A.P;
	BOOL Judge (line X1,line X2,line i) {point t=cross (X1,X2);
Return i.v* (T-I.P) >0;
	void push (line x) {while (Head<tail&&!judge (t1,t2,x)) tail--;
	while (Head<tail&&!judge (h1,h2,x)) head++;
Que[++tail]=x;
	} void HPI () {int i;
	Sort (a+1,a+1+tot,cmp);
	a[0].angle=-10.12345;
	for (i=1,cnt=0;i<=tot;i++) if (a[i].angle!=a[i-1].angle) a[++cnt]=a[i];
	que[1]=a[1];head=tail=1;
	for (i=2;i<=cnt;i++) push (A[i]);
	while (Head<tail&&!judge (T1,T2,H1)) tail--;
	while (Head<tail&&!judge (H1,H2,T1)) head++;
	que[tail+1]=que[head];cnt=0;
for (i=head;i<=tail;i++) P[++cnt]=cross (que[i],que[i+1]);
	Double area () {double s=0;
	if (cnt<3) return s;
	P[CNT+1]=P[1];
	for (int i=1;i<=cnt;i++) s+=p[i]*p[i+1];
return Fabs (s)/2;
	int main () {freopen ("2618.in", "R", stdin);
	scanf ("%d", &n);
	tot=0;
		for (i=1;i<=n;i++) {scanf ("%d", &m);
		scanf ("%lf%lf", &p1.x,&p1.y);
		H=P1; for (j=1;j<m;J + +) {scanf ("%lf%lf", &p2.x,&p2.y);
			A[++TOT].P=P1;A[TOT].V=P2-P1;
			A[tot].angle=atan2 (a[tot].v.y,a[tot].v.x);
		P1=P2;
		} p2=h;
		A[++TOT].P=P1;A[TOT].V=P2-P1;
	A[tot].angle=atan2 (a[tot].v.y,a[tot].v.x);
	} HPI ();
printf ("%.3lf", Area ()); }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.