luogu1355 神秘大三角

时间:2022-08-22 20:42:56

题解:

计算几何入门题

按逆时针方向访问三角形的边

然后作叉积判断点是否在边的顺时针方向

叉积和点积都有分配率 但不满足结合律

代码:

#include <bits/stdc++.h>
using namespace std;
#define rint register int
#define IL inline
#define rep(i,h,t) for (int i=h;i<=t;i++)
#define dep(i,t,h) for (int i=t;i>=h;i--)
#define me(x) memset(x,0,sizeof(x))
#define mid ((h+t)>>1)
namespace IO{
char ss[<<],*A=ss,*B=ss;
IL char gc()
{
return A==B&&(B=(A=ss)+fread(ss,,<<,stdin),A==B)?EOF:*A++;
}
template<class T>void read(T &x)
{
rint f=,c; while (c=gc(),c<||c>) if (c=='-') f=-; x=(c^);
while (c=gc(),c>&&c<) x=(x<<)+(x<<)+(c^); x*=f;
}
};
using namespace IO;
struct Point{
int x,y;
Point(){};
Point(int x1,int y1)
{
x=x1,y=y1;
}
Point operator +(const Point b)const
{
return Point(x+b.x,y+b.y);
}
Point operator -(const Point b)const
{
return Point(x-b.x,y-b.y);
}
int operator *(const Point b)const
{
return b.x*x+b.y*y;
}
int operator ^(const Point b)const
{
return x*b.y-y*b.x;
}
bool operator ==(const Point b)const
{
if (y==b.y&&x==b.x) return(); else return();
}
};
struct Line{
Point x,y;
Line() {};
Line(Point x1,Point y1)
{
x=x1,y=y1;
}
};
int main()
{
int x1,y1,x2,y2,x3,y3,x,y;
Point p1,p2,p3,p;
read(x1); read(y1); p1=Point(x1,y1);
read(x2); read(y2); p2=Point(x2,y2);
read(x3); read(y3); p3=Point(x3,y3);
read(x); read(y); p=Point(x,y);
if (((p3-p1)^(p2-p1))>) swap(p3,p1);
if (p==p1||p==p2||p==p3)
{
cout<<<<endl;
exit();
}
int tt=;
if (((p3-p1)^(p-p1))>) tt=;
if (((p3-p1)^(p-p1))==) tt=;
if (((p1-p2)^(p-p2))>) tt=;
if (((p1-p2)^(p-p2))==) tt=;
if (((p2-p3)^(p-p3))>) tt=;
if (((p2-p3)^(p-p3))==) tt=;
cout<<tt<<endl;
return ;
}