POJ 4048 Chinese repeating Crossbow segment specification intersection judgment

Source: Internet
Author: User
Tags min

Test instructions

For n segments and initial points, the maximum number of lines emitted by the initial point can be crossed (even through the intersection).

Analysis:

Enumerating the end points of a segment, judging whether the segments intersect, requires a rigorous template.

Code:

POJ 4048//sep9 #include <iostream> using namespace std;
typedef long Long LL;
const LL maxn=2000;

const LL maxl=40028; struct P {ll x, y;}

A[maxn],b[maxn],p;
ll Tx,ty;

int n;
	ll det (P a,p b,p c) {ll x1=b.x-a.x;
	ll Y1=b.y-a.y;
	ll x2=c.x-a.x;
	ll Y2=c.y-a.y;
return x1*y2-x2*y1;
	} int Get_sign (ll x) {if (x==0) return 0;
Return x>0?1:-1; } ll Mymax (ll A,ll b) {return a>b?a:b;} ll mymin (ll A,ll b) {return a>b?b:a;} int between (P mid,p a,p b) {R Eturn Mid.x<=max (a.x,b.x) &&mid.y<=max (A.Y,B.Y) &&mid.x>=min (a.x,b.x) &&mid.y> 
=min (A.Y,B.Y);
 	} bool Crossed (P a,p b,p c,p d) {int d1,d2,d3,d4;
 	D1=get_sign (Det (a,b,c));
 	D2=get_sign (Det (a,b,d));
 	D3=get_sign (Det (c,d,a));	 
	D4=get_sign (Det (c,d,b));
	if ((D1^D2) ==-2&& (D3^D4) ==-2) return true;
	   if ((D1==0&&between (c,a,b)) | |
	   (D2==0&&between (d,a,b)) | |
	   (D3==0&&between (a,c,d)) | |
		(D4==0&&between (b,c,d)))
	return true; return FAlse;
	} int Process (P dir) {int cnt=0;
	dir.x=p.x+ (dir.x-p.x) *10000;
	dir.y=p.y+ (DIR.Y-P.Y) *10000;
	if (DIR.X==P.X&AMP;&AMP;DIR.Y==P.Y) return 0;
	for (int i=1;i<=n;++i) if (crossed (P,dir,a[i],b[i])) ++cnt;
return CNT;
	} int main () {int i,cases;
	scanf ("%d", &cases);
		while (cases--) {scanf ("%d", &n);
		for (I=1;i<=n;++i) scanf ("%lld%lld%lld%lld", &a[i].x,&a[i].y,&b[i].x,&b[i].y);			
		scanf ("%lld%lld", &p.x,&p.y);
		int ans=0;
			for (i=1;i<=n;++i) {Ans=max (ans,process (A[i]));
		Ans=max (Ans,process (b[i));
	} printf ("%d\n", ans);
} 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.