Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- class Point{
- public:
- int x,y;
- Point(){}
- Point(int a, int b){
- x=a;
- y=b;
- }
- };
- int okret(Point a, Point b, Point c){
- if((b.y-a.y)*(c.x-b.x)-(c.y-b.y)*(b.x-a.x)<0) return -1;
- if((b.y-a.y)*(c.x-b.x)-(c.y-b.y)*(b.x-a.x)>0) return 1;
- return 0;
- }
- bool naSegmentu(Point a,Point b, Point toCheck){
- if(toCheck.x<min(a.x,b.x) || toCheck.x>max(a.x,b.x) || toCheck.y<min(a.y,b.y) || toCheck.y>max(a.y,b.y)) return false;
- return true;
- }
- bool dodirujuSe(Point a, Point b, Point c, Point d){
- if(okret(a,b,c)!=okret(a,b,d) && okret(c,d,a)!=okret(c,d,b)) return true;
- if(okret(a,b,c)==0 && naSegmentu(a,b,c)) return true;
- if(okret(a,b,d)==0 && naSegmentu(a,b,d)) return true;
- if(okret(c,d,a)==0 && naSegmentu(c,d,a)) return true;
- if(okret(c,d,b)==0 && naSegmentu(c,d,b)) return true;
- return false;
- }
- int main(){
- Point a, b, c, d;
- cin >> a.x >> a.y;
- cin >> b.x >> b.y;
- cin >> c.x >> c.y;
- cin >> d.x >> d.y;
- cout<<dodirujuSe(a,b,c,d)<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement