标签:lse 否则 name div 报错 line ble bit get
第1行:一个数T,表示输入的测试数量(1 <= T <= 1000) 第2 - T + 1行:每行8个数,x1,y1,x2,y2,x3,y3,x4,y4。(-10^8 <= xi, yi <= 10^8) (直线1的两个端点为x1,y1 | x2, y2,直线2的两个端点为x3,y3 | x4, y4)
输出共T行,如果相交输出"Yes",否则输出"No"。
2 1 2 2 1 0 0 2 2 -1 1 1 1 0 0 1 -1
Yes No
注意判断还是可以的,
记得不要变量名为y1
跟c++ 里面的变量名重复了.
所以会报错.
1 #include <bits/stdc++.h> 2 #define ll long long int 3 using namespace std; 4 5 double get_k(double x1, double yy, double x2, double y2){ 6 return (yy-y2)/(x1-x2); 7 } 8 9 int t; 10 double x1, yy, x2, y2, x3, y3, x4, y4; 11 int main(){ 12 cin>>t; 13 while(t--){ 14 cin>>x1>>yy>>x2>>y2>>x3>>y3>>x4>>y4; 15 double k1 = get_k(x1, yy, x2, y2); 16 double d1 = yy - k1 * x1; 17 18 double k2 = get_k(x3, y3, x4, y4); 19 double d2 = y3 - k2 * x3; 20 21 if(k1 == k2){ 22 if(d1 == d2 && (y3 == (k1*x3 + d1) || y4 == (k1*x4 + d1) || yy == (k2*x1 + d2) || y2 == (k2*x2 + d2))){ 23 cout<<"Yes"<<endl; 24 }else{ 25 cout<<"No"<<endl; 26 } 27 }else{ 28 double xx = (d2 - d1)/(k1 - k2); 29 if(xx >= min(x1, x2) && xx <= max(x1, x2) && xx >= min(x3, x4) && xx <= max(x3, x4) ){ 30 cout<<"Yes"<<endl; 31 }else{ 32 cout<<"No"<<endl; 33 } 34 } 35 } 36 return 0; 37 }
标签:lse 否则 name div 报错 line ble bit get
原文地址:https://www.cnblogs.com/zllwxm123/p/9904499.html