luogu1355 神秘大三角
生活随笔
收集整理的這篇文章主要介紹了
luogu1355 神秘大三角
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題解:
計算幾何入門題
按逆時針方向訪問三角形的邊
然后作叉積判斷點是否在邊的順時針方向
叉積和點積都有分配率 但不滿足結(jié)合律
代碼:
#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[1<<24],*A=ss,*B=ss;IL char gc(){return A==B&&(B=(A=ss)+fread(ss,1,1<<24,stdin),A==B)?EOF:*A++;}template<class T>void read(T &x){rint f=1,c; while (c=gc(),c<48||c>57) if (c=='-') f=-1; x=(c^48);while (c=gc(),c>47&&c<58) x=(x<<3)+(x<<1)+(c^48); 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(1); else return(0);} }; 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))>0) swap(p3,p1); if (p==p1||p==p2||p==p3){cout<<4<<endl;exit(0);}int tt=1;if (((p3-p1)^(p-p1))>0) tt=2;if (((p3-p1)^(p-p1))==0) tt=3;if (((p1-p2)^(p-p2))>0) tt=2;if (((p1-p2)^(p-p2))==0) tt=3;if (((p2-p3)^(p-p3))>0) tt=2;if (((p2-p3)^(p-p3))==0) tt=3; cout<<tt<<endl;return 0; }?
轉(zhuǎn)載于:https://www.cnblogs.com/yinwuxiao/p/9986072.html
總結(jié)
以上是生活随笔為你收集整理的luogu1355 神秘大三角的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于开源中国手机App的说明
- 下一篇: Sliverlight MD5