hrbustOJ 围困(判断点是否在三角形内)

/* * 题目要求:判断点是否在三角形内 * 可利用叉乘判断拐向来解决 * auther:Try86 */ #include <cstdio> #include <iostream> using namespace std; struct point { int x; int y; }A, B, C, D; int crossProd(point A, point B, point C) { return (B.x-A.x)*(C.y-A.y) - (B.y-A.y)*(C.x-A.x); } bool inTrangle() { if (crossProd(D, A, B)<0 && crossProd(D, B, C)<0 && crossProd(D, C, A)<0) return true; if (crossProd(D, A, B)>0 && crossProd(D, B, C)>0 && crossProd(D, C, A)>0) return true; return false; } int main() { while (scanf("%d%d%d%d%d%d%d%d", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y, &D.x, &D.y) != EOF) { bool yes = inTrangle(); if (yes) printf ("Die\n"); else printf ("Live\n"); } return 0; }