scoiday1t3&&bzoj4445 Xiao Convex want to run __ geometry

Source: Internet
Author: User

Geometry problem Ah, is said to be bare half plane, but I still WA several hair.


The probability of a point in a polygon that is smaller than the other edge by a certain point, (with Range/total area).


Then you can set the point for (X,y), to all sides of the area to express, and then establish unequal relationships, after the reduced point we can get a series of inequalities on X,y, such as Ax+by<c, and then engage in a half plane.


However, there are two bugs I did not consider, one is to ensure (x,y) points in the convex polygon inside, how to guarantee. First, all the half planes are represented as straight lines, the left side of the line represents a half plane, and then all the edges are added in, which also constitute a string of unequal relationships.

I did not consider this situation, the probability is too large, why. Because the range of this point to the outside of the polygon ah.


One of the above schemes corresponds to the first, space is twice times the second, and time is almost the same.


The second way, we can only add the limit of the first side, the rest of the side are no matter why it is feasible to do so. It can be perceptual to understand that, if on the other side, it must not be to the first edge of the smallest, so in the unequal relationship between the constraints, simply can not move. (You can paint it properly)

Such time and space are saved.



The second bug I have been doing for a long time, because the previous sample can be passed, but made a few hair wa (and contributed so many WA, really ashamed.) )

Then constantly generate data (in fact, the end is their own hand to push a group of data), found that their output is actually "Nan", well, it must be hung, and then I put the data into the debugging, I found that I calculate unequal relationship ax+by+c<0, B may be 0, In this case I use the starting point of the denominator has a B, divided by 0, it is illegal, and then GG.


After pulling out the second bug, the decision comes again, and the result is a.


Then boredom came to find out the cause of the bug (a few more, and WA a few times).

In the first bug, if you want to create an inequality for all the edges, you need to open the space twice times.


Make a series of unequal relationships, and directly cover the half plane.

#include <cstdio> #include <algorithm> #include <iostream> #include <cmath> #define EPS 1e-10
using namespace Std;
const int MAXN=200000+20;
	int dcmp (double x) {if (Fabs (x) <eps) return 0;
else return x<0?-1:1;
	} struct point {double x,y;
	Point () {} point (double _x,double _y) {x=_x;y=_y;}
	Point operator + (const point &b) {return point (X+B.X,Y+B.Y);}
	Point operator-(const point &b) {return point (X-B.X,Y-B.Y);}
Point operator * (const double &b) {return point (X*b,y*b);}};
	struct line {point p,v;
	Double ang;
	Line () {} line (point _p,point _v) {p=_p;v=_v;ang=atan2 (v.y,v.x);}
	BOOL operator < (const line &l) Const {return ang<l.ang;
}
}; Double Cross (point A,point b) {return a.x*b.y-a.y*b.x;} double dot (point A,point b) {return a.x*b.x+a.y*b.y;} bool Onleft (l
INE L,point p) {return dcmp (Cross (L.V,P-L.P)) >0;}/* (Y1+Y4-Y2-Y3) x+ (x2+x3-x1-x4) y+x1y2-x2y1+x4y3-x3y4<0 * * Point Getsec (Point p1,point v1,point p2,point v2) {Double X=cross (P2-P1,V2)/cross (V1,V2);
return p1+v1*x;
Double pans;
Line L[MAXN];
Point T[MAXN];
Line Q[MAXN];
	void Hp (line *l,int N) {sort (l+1,l+n+1);
	int first,last;		
	Point P[MAXN];
	Q[LAST=FIRST=0]=L[1];
		for (int i=2;i<=n;i++) {while (First<last&&!onleft (l[i],p[last-1)) last--;
		while (First<last&&!onleft (L[i],p[first])) first++;
		Q[++last]=l[i];
			if (dcmp (Cross (Q[LAST].V,Q[LAST-1].V)) ==0) {last--;
			if (!onleft (L[i],p[last-1])) q[last]=l[i]; 
		Equivalent to if (Onleft (Q[LAST],L[I].P)) q[last]=l[i];
	} if (First<last) p[last-1]=getsec (Q[LAST].P,Q[LAST].V,Q[LAST-1].P,Q[LAST-1].V);
	while (First<last&&!onleft (Q[first],p[last-1])) last--;
		if (last-first<=1) {printf ("0.0000\n");
	return;
	} p[last]=getsec (Q[LAST].P,Q[LAST].V,Q[FIRST].P,Q[FIRST].V);
	Double ans=0;
	for (int i=first+1;i<last;i++) {ans+=fabs (Cross (P[i]-p[first],p[i+1]-p[first)));
	} ans*=0.5;
printf ("%.4lf\n", Ans/pans);
int cnt;
	void pre (int n) {cnt=0; Double x1=t[1].X,Y1=T[1].Y;
	Double x2=t[2].x,y2=t[2].y;
		for (int i=2;i<=n;i++) {double x3=t[i].x,y3=t[i].y;
		Double x4=t[i+1].x,y4=t[i+1].y;
		Double a=y1+y4-y2-y3;
		Double b=x2+x3-x1-x4;
		Double C=x1*y2-x2*y1+x4*y3-x3*y4; 
		ax+by+c<0//Direction vector (-b,a);
		Make ax+by+c=0 to the left of Ax+by+c point P;if (dcmp (b)!=0) P=point (0,-c/b);
		else P=point (-c/a,0);
		Point V;v=point (-b,a); 
	L[++cnt]=line (P,V);
}//l[++cnt]=line (t[1],t[2]-t[1]);//for (int i=1;i<=n;i++) l[++cnt]=line (t[i],t[i+1]-t[i));
	int main () {int n;
	scanf ("%d", &n);
	for (int i=1;i<=n;i++) scanf ("%lf%lf", &t[i].x,&t[i].y);
	pans=0;
	for (int i=2;i<n;i++) {pans+=fabs (Cross (t[i]-t[1],t[i+1]-t[1)));
	} pans*=0.5;
	T[N+1]=T[1];
	Pre (n);
	
	Hp (L,CNT);
return 0; }


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.