Bzoj 4445 [Scoi2015] small convex want to run half plane to turn __ac Road

Source: Internet
Author: User
A semilinear equation for solving inequalities in a plane
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <
Cmath> #define EPS 1e-10 #define MAXN 500021 using namespace std;
int N,cnt,tot;
Double all;
	struct p{double x,y;
	void Init () {scanf ("%lf%lf", &x,&y);}
P (Double a=0,double b=0): X (a), Y (b) {}}P[MAXN];
typedef P VEC;
Double operator* (P a,p b) {return a.x*b.y-a.y*b.x;} vec operator-(P a,p b) {return VEC (A.X-B.X,A.Y-B.Y);} P operator+ (P A,vec b) {return P (A.X+B.X,A.Y+B.Y);} vec operator/(VEC a,double t) {return VEC (a.x/t,a.y/t);} VEC operator* ( 
	VEC a,double t) {return VEC (a.x*t,a.y*t);} bool dcmp (double a,double b) {return fabs (a-b) <=eps;} struct line{P A;vec b;
	Double slop;
		BOOL operator< (const line& y) const{if (Fabs (slop-y.slop) >eps) return slop<y.slop;
	Return b* (y.a-a) <0;

}}L[MAXN],Q[MAXN];
	void Build () {scanf ("%d", &n);
	P[1].init (), P[2].init ();
	Double a,b,c,x,y;p[n+1]=p[1];
		for (int j,i=3;i<=n+1;i++) {if (i<=n) p[i].init (); J=i-1;
		A=P[1].Y-P[2].Y-P[J].Y+P[I].Y;
 		b=p[2].x-p[1].x-p[i].x+p[j].x;
		C= (P[2].X*P[1].Y-P[1].X*P[2].Y+P[J].X*P[I].Y-P[I].X*P[J].Y) *-1; L[++cnt].a= Fabs (a) >eps?
		P (-c/a,0): P (0,-c/b);
	L[cnt].b=vec (-b,a);
	
	for (int i=1;i<=n;i++) all+=p[i]*p[i+1];
		for (int i=1;i<=n;i++) {l[++cnt].a=p[i];
	L[cnt].b=p[i+1]-p[i];
	for (int i=1;i<=cnt;i++) l[i].slop=atan2 (l[i].b.y,l[i].b.x);
	Sort (l+1,l+1+cnt); for (int i=1;i<=cnt;i++) {if!dcmp (l[i].slop,l[i-1].slop) | |
	i==1) L[++tot]=l[i];
}cnt=tot;
	P Q (line aa,line bb) {p A=AA.A,B=BB.A;
	VEC a=aa.b,b=bb.b,c=a-b;
	Double k= (b*c)/(A*B);
return a+a*k;
	BOOL Judge (line A,line B,line c) {P x=q (a,b);
Return (X-C.A) *c.b>0;
	} void Solve () {q[1]=l[1];
	int l=1,r=1;
		for (int i=2;i<=cnt;i++) {while (L<r&&judge (q[r-1],q[r],l[i)) r--;
		while (L<r&&judge (Q[l],q[l+1],l[i])) l++;
	Q[++r]=l[i];
	while (L<r&&judge (Q[r-1],q[r],q[l])) r--;
	q[r+1]=q[l];tot=0; for (int i=l;i<=r;i++) {p[++tot]=q (q[I],q[i+1]);
}P[TOT+1]=P[1];
	int main () {build ();
	Solve ();
	Double ans=0;
	for (int i=1;i<=tot;i++) ans+=p[i]*p[i+1];
	if (tot<3) {puts ("0.0000"); return 0;}
	All=fabs (All), ans=fabs (ans);
	Ans=ans/all;
	printf ("%.4lf", ans);
return 0; }

Related Article

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.