Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <map>
- #include <stdio.h>
- #include <string>
- #include <algorithm>
- #include <set>
- #include <ctime>
- using namespace std;
- #define loop(i,x,n) for (int i = x ; i<=n ; i++)
- #define dloop(i,x,n) for (int i = x ; i>=n ; i--)
- #define pb push_back
- #define mp make_pair
- #define pi 3.1415926535897932384626433832795
- #define size(x) (int) x.size()
- #define ll long long
- #define y1 y23452345423
- const long long inf=1e9;
- class point{
- public:
- int x,y;
- } p1,p2,p3,p4;
- bool RectanglesIntersects(double x1,double y1, double x2, double y2,
- double x3,double y3, double x4, double y4)
- {
- if ((x3 - x2)*(x4 - x1) > 0) return false;
- if ((y3 - y2)*(y4 - y1) > 0) return false;
- return true;
- }
- bool intersect(double x1,double y1, double x2, double y2,
- double x3,double y3, double x4, double y4)
- {
- double ABx, ABy, ACx, ACy, ADx, ADy;
- double CAx, CAy, CBx, CBy, CDx, CDy;
- double ACxAB, ADxAB, CAxCD, CBxCD;
- if (!RectanglesIntersects(min(x1,x2),min(y1,y2),max(x1,x2),max(y1,y2),
- min(x3,x4),min(y3,y4),max(x3,x4),max(y3,y4))) return 0;
- ACx = x3 - x1; ACy = y3 - y1;
- ABx = x2 - x1; ABy = y2 - y1;
- ADx = x4 - x1; ADy = y4 - y1;
- CAx = x1 - x3; CAy = y1 - y3;
- CBx = x2 - x3; CBy = y2 - y3;
- CDx = x4 - x3; CDy = y4 - y3;
- ACxAB = ACx * ABy - ACy * ABx;
- ADxAB = ADx * ABy - ADy * ABx;
- CAxCD = CAx * CDy - CAy * CDx;
- CBxCD = CBx * CDy - CBy * CDx;
- return ACxAB * ADxAB <= 0 && CAxCD * CBxCD <= 0;
- }
- int main()
- {
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- scanf("%d%d%d%d%d%d%d%d",&p1.x,&p1.y,&p2.x,&p2.y,&p3.x,&p3.y,&p4.x,&p4.y);
- if (intersect(p1.x,p1.y,p2.x,p2.y,p3.x,p3.y,p4.x,p4.y)) printf("Yes\n");
- else printf("No\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement