View Code
/*
*  题目要求:判断点是否在三角形内
*  可利用叉乘判断拐向来解决 
*  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;
}

 

相关文章:

  • 2021-11-05
  • 2022-01-08
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2021-04-30
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-05
相关资源
相似解决方案