您的位置:首页 > 其它

51nod 1264 线段相交

2017-05-10 20:35 183 查看
1264 线段相交

基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注

给出平面上两条线段的两个端点,判断这两条线段是否相交(有一个公共点或有部分重合认为相交)。 如果相交,输出”Yes”,否则输出”No”。

Input

第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)

Output

输出共T行,如果相交输出”Yes”,否则输出”No”。

Input示例

2

1 2 2 1 0 0 2 2

-1 1 1 1 0 0 1 -1

Output示例

Yes

No

#include <stdio.h>
#include <bits/stdc++.h>
#define read(); freopen("C:\\Users\\Administrator\\Desktop\\input.txt","r",stdin);
using namespace std;
typedef long long ll;
int t;
class pion{
public:
ll x,y;
};
pion a,b,c,d;
ll f(pion a,pion b,pion c){
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
int solve(){
double p1,p2,p3,p4;
p1=f(a,b,c);
p2=f(a,b,d);
p3=f(c,d,a);
p4=f(c,d,b);
//  cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;
if(p1*p2<=0 && p3*p4<=0)
return 1;
return 0;
}
int main()
{
//read();
cin>>t;

while(t--){
cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>d.x>>d.y;
if(solve()){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
}
return 0;
}


这里写代码片

“`
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息