Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <map>
  5. #include <stdio.h>
  6. #include <string>
  7. #include <algorithm>
  8. #include <set>
  9. #include <ctime>
  10.  
  11. using namespace std;
  12.  
  13. #define loop(i,x,n) for (int i = x ; i<=n ; i++)
  14. #define dloop(i,x,n) for (int i = x ; i>=n ; i--)
  15. #define pb push_back
  16. #define mp make_pair
  17. #define pi 3.1415926535897932384626433832795
  18. #define size(x) (int) x.size()
  19. #define ll long long
  20. #define y1 y23452345423
  21. const long long inf=1e9;
  22.  
  23. class point{
  24. public:
  25. int x,y;
  26. } p1,p2,p3,p4;
  27. bool RectanglesIntersects(double x1,double y1, double x2, double y2,
  28.  
  29. double x3,double y3, double x4, double y4)
  30. {
  31. if ((x3 - x2)*(x4 - x1) > 0) return false;
  32.  
  33. if ((y3 - y2)*(y4 - y1) > 0) return false;
  34.  
  35. return true;
  36. }
  37. bool intersect(double x1,double y1, double x2, double y2,
  38.  
  39. double x3,double y3, double x4, double y4)
  40. {
  41. double ABx, ABy, ACx, ACy, ADx, ADy;
  42.  
  43. double CAx, CAy, CBx, CBy, CDx, CDy;
  44.  
  45. double ACxAB, ADxAB, CAxCD, CBxCD;
  46.  
  47. if (!RectanglesIntersects(min(x1,x2),min(y1,y2),max(x1,x2),max(y1,y2),
  48.  
  49. min(x3,x4),min(y3,y4),max(x3,x4),max(y3,y4))) return 0;
  50.  
  51. ACx = x3 - x1; ACy = y3 - y1;
  52.  
  53. ABx = x2 - x1; ABy = y2 - y1;
  54.  
  55. ADx = x4 - x1; ADy = y4 - y1;
  56.  
  57. CAx = x1 - x3; CAy = y1 - y3;
  58.  
  59. CBx = x2 - x3; CBy = y2 - y3;
  60.  
  61. CDx = x4 - x3; CDy = y4 - y3;
  62.  
  63. ACxAB = ACx * ABy - ACy * ABx;
  64.  
  65. ADxAB = ADx * ABy - ADy * ABx;
  66.  
  67. CAxCD = CAx * CDy - CAy * CDx;
  68.  
  69. CBxCD = CBx * CDy - CBy * CDx;
  70.  
  71. return ACxAB * ADxAB <= 0 && CAxCD * CBxCD <= 0;
  72.  
  73. }
  74. int main()
  75. {
  76. freopen("input.txt","r",stdin);
  77. freopen("output.txt","w",stdout);
  78. 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);
  79. if (intersect(p1.x,p1.y,p2.x,p2.y,p3.x,p3.y,p4.x,p4.y)) printf("Yes\n");
  80. else printf("No\n");
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement