P1355 Mysterious Grand Triangle

Source: Internet
Author: User

Title Description

Determines the position relationship of a point to a known triangle.

Input output Format input format:

First three lines: one coordinate per line representing the three vertices of the triangle

Line four: The coordinates of a point, try to determine the location of the point and the first three points around the triangle position relationship

(See examples)

All coordinate values are integers.

Output format:

If the point is within the triangle (excluding the boundary), the output is 1;

If the point is outside the triangle (excluding the boundary), the output is 2;

If the point is on the triangle boundary (without vertices), the output is 3;

If the point is on the triangle vertex, output 4.

Input and Output Sample input example # #:
(0,0) (3,0) (0,3) (a)
Sample # # of output:
1
Description

"Data size and conventions"

For 100% data, 0<= the horizontal and vertical coordinates of all points <=100

The data is weak, how can the public engage in a. Just practice your train of thought.
//The AC code of his own brain hole#include <cstdio>#include<cmath>using namespacestd;intRead () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}Const DoublePi=acos (-1);structnode{intx, y; BOOL operator==(ConstNode &a) {        returnx==a.x&&y==a.y; }}a,b,c,d;voidinit () {a.x=read (); a.y=read (); b.x=read (); b.y=read (); c.x=read (); c.y=read (); D.x=read ();D. y=read ();}DoubleSlop (node A,node b) {if(a.x==b.x)return1e9; return(Double) (A.Y-B.Y)/(Double) (a.x-b.x);}BOOLDeal (node A,node b) {//High Accuracy Requirementsnode t1,t2; t1.x=a.x-d.x;t1.y=a.y-D.y; t2.x=b.x-d.x;t2.y=b.y-D.y; DoubleXiang= (Double) (t1.x*t2.x+t1.y*t2.y); DoubleMo=sqrt ((T1.X*T1.X+T1.Y*T1.Y) * (t2.x*t2.x+t2.y*t2.y)); Doublecita=xiang/mo; if(ACOs (CITA) ==pi)return 1; Else return 0;}voidWork () {if(d==a| | d==b| | D==c) {puts ("4");return ;} //dot product seeking angle 180 common line    if(Deal (A, b)) {Puts ("3");return ;} if(Deal (A,C)) {Puts ("3");return ;} if(Deal (B,C)) {Puts ("3");return ;} //determine if the point is in the triangle//http://files.cnblogs.com/files/shenben/%E5%88%A4%E6%96%AD%E7%82%B9%E6%98%AF%E5%90%A6%E5%9C%A8%E4%B8%89%E8% A7%92%e5%bd%a2%e4%b8%ad.sh    if(Slop (A, B)!=slop (a,c) &&slop (a,d)! =Slop (b,c)&& (Slop (a,d)-slop (A, B)) * (a.x-b.x) * (Slop (a,d)-slop (a,c)) * (a.x-c.x) <=0&& (Slop (a,d)-slop (b,c)) * (a.x-d.x) * (Slop (b,d)-slop (b,c)) * (b.x-d.x) <0) {puts ("1"); }    ElsePuts"2");}intMain () {init ();    Work (); return 0;}

//a better idea of the AC code#include <cstdio>#include<cstdlib>#include<cmath>using namespacestd;intRead () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}structnode{intx, y; BOOL operator==(ConstNode &a) {        returnx==a.x&&y==a.y; }}a,b,c,d;voidinit () {a.x=read (); a.y=read (); b.x=read (); b.y=read (); c.x=read (); c.y=read (); D.x=read ();D. y=read ();}intCalcConstNode &a,ConstNode &b,ConstNode &c) {//Cross product    returnABS ((A.X*B.Y+B.X*C.Y+C.X*A.Y)-(a.x*c.y+b.x*a.y+c.x*b.y));}voidWork () {if(d==a| | d==b| | D==c) puts ("4"); Else{//Low Accuracy Requirements        if(Calc (d,a,b) +calc (d,a,c) +calc (d,b,c)!=calc (a,b,c)) puts ("2");//range, must be outside the triangle        Else if(!calc (d,a,b) | |! Calc (d,a,c) | |! Calc (d,b,c)) puts ("3");//cross Product = 0, on the line segment (not rigorous ...)        ElsePuts"1");//only inside the triangle .    } }intMain () {init ();    Work (); return 0;}

P1355 Mysterious Grand Triangle

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.