关于网站建设方案的案例,属于网络营销的特点是,可以直接进入网站的正能量照片,夹克定制公司UVA378 Intersecting Lines 题解
怎么这么多点斜式邪教啊。
解法
在计算几何中#xff0c;我们应该尽可能地避免使用浮点数的计算#xff0c;尽可能地使用向量计算。
本篇题解默认读者具有向量基础。
为了方便讲解#xff0c;我们将输入的四个点分别记作 A , B , C , …UVA378 Intersecting Lines 题解
怎么这么多点斜式邪教啊。
解法
在计算几何中我们应该尽可能地避免使用浮点数的计算尽可能地使用向量计算。
本篇题解默认读者具有向量基础。
为了方便讲解我们将输入的四个点分别记作 A , B , C , D A,B,C,D A,B,C,D。
考虑两条直线 A B , C D AB,CD AB,CD 何时平行。根据向量叉乘的几何意义如果 A B → × C D → 0 \overrightarrow{AB} \times \overrightarrow{CD}0 AB ×CD 0则两直线平行。
直线重合是在直线平行的基础上如果 C , D C,D C,D 中任一点在直线 A B AB AB 上则两直线平行。即 A B → × A C → 0 \overrightarrow{AB} \times \overrightarrow{AC}0 AB ×AC 0这里取点 C C C。
剩下的情况就是直线相交了。如图设两直线交点为 E E E。 根据小学四年级雾学的燕尾模型 A E E B S Δ A D C S Δ B D C \dfrac{AE}{EB}\dfrac{S_{\Delta ADC}}{S_{\Delta BDC}} EBAESΔBDCSΔADC所以 A E A B S Δ A D C S Δ A D C S Δ B D C \dfrac{AE}{AB}\dfrac{S_{\Delta ADC}}{S_{\Delta ADC}S_{\Delta BDC}} ABAESΔADCSΔBDCSΔADC三角形面积可以用叉积轻松求出。
所以两直线交点为 ( X A ( X B − X A ) × A E A B , Y A ( Y B − Y A ) × A E A B ) (X_A(X_B-X_A) \times \dfrac{AE}{AB},Y_A(Y_B-Y_A) \times \dfrac{AE}{AB}) (XA(XB−XA)×ABAE,YA(YB−YA)×ABAE)。
最后提一句这道题是早期 UVA 题没有自动忽略文末换行这题需要有文末换行。
代码
#includebits/stdc.h
namespace fast_IO
{/*** 省略了一部分*/inline void read(int x,char cGetchar()){bool fc!45;x0;while(c48 or c57) cGetchar(),fc!45;while(c48 and c57) x(x3)(x1)(c^48),cGetchar();xf?x:-x;}inline void write(int x){if(x0) Putchar(45),x-x;if(x10) write(x/10),x%10;Putchar(x^48);}inline void read(__int128 x,char cGetchar()){bool fc!45;x0;while(c48 or c57) cGetchar(),fc!45;while(c48 and c57) x(x3)(x1)(c^48),cGetchar();xf?x:-x;}inline void write(__int128 x){if(x0) Putchar(45),x-x;if(x10) write(x/10),x%10;Putchar(x^48);}inline bool inrange(const char ch){if(ch33 ch126) return true;return false;}inline void read(std::string st,char cGetchar()){st.clear();while(!inrange(c)) cGetchar();while(inrange(c)) stc,cGetchar();}inline void write(std::string st){for(int i0;ist.size();i) Putchar(st[i]);}inline void read(char ch){chGetchar();while(!inrange(ch)) chGetchar();}inline void write(const char ch){Putchar(ch);}inline void write(double x,int fix2){xx0?my_round[fix1]:-my_round[fix1],write((__int128)x),xx0?x:-x,x-(__int128)x;if(fix){Putchar(46);while(fix--) x*10,Putchar(((int)x)^48),x-(int)x;}}class fastin{public:templatetypename Tinline fastin operator(T x){read(x);return *this;}};class fastout{public:templatetypename Tinline fastout operator(T x){write(x);return *this;}};fastin in;fastout out;
};
using namespace fast_IO;
int n;
struct point
{int x,y;point(){xy0;}point(int x,int y){this-xx,this-yy;}inline point operator-(const point rhs) const{return point(x-rhs.x,y-rhs.y);}inline int operator*(const point rhs){return x*rhs.y-y*rhs.x;}
};
inline int sgn(int x)
{return x0?0:(x0?1:-1);
}
struct seg
{point s,t;
};
seg a,b;
inline void calc()
{double ix,iy,rat;rat(b.t-a.s)*(b.s-a.s)*1.0/((b.t-a.s)*(b.s-a.s)-(b.t-a.t)*(b.s-a.t));ixa.s.x*1.0(a.t.x-a.s.x)*rat,iya.s.y*1.0(a.t.y-a.s.y)*rat;outPOINT ix iy\n;
}
int main()
{inn,outINTERSECTING LINES OUTPUT\n;for(int i1;in;i){ina.s.xa.s.ya.t.xa.t.yb.s.xb.s.yb.t.xb.t.y;if((a.t-a.s)*(b.t-b.s)0){if((a.t-a.s)*(b.s-a.s)0) outLINE\n;else outNONE\n;}else calc();}outEND OF OUTPUT\n;fwrite(Ouf,1,p3-Ouf,stdout),fflush(stdout);return 0;
}