Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. struct point
  4. {
  5. long long x,y;
  6. };
  7. struct vect
  8. {
  9. long long x,y;
  10. };
  11.  
  12. vect v(const point &a,const point &b)
  13. {
  14. vect ans;
  15. ans.x=b.x-a.x;
  16. ans.y=b.y-a.y;
  17. return ans;
  18. }
  19. long long vector_proizv(vect &a,vect &b)
  20. {
  21. return a.x*b.y-a.y*b.x;
  22. }
  23. bool cmp(const point &a,const point &b)
  24. {
  25. return ((a.x==b.x)&&(a.y==b.y));
  26. }
  27. long long skalar_proizv(vect &a,vect &b)
  28. {
  29. return a.x*b.x+a.y*b.y;
  30. }
  31. int sign(const long long &a)
  32. {
  33. if(a>=0)
  34. {
  35. return 1;
  36. }
  37. if(a==0)
  38. {
  39. return 0;
  40. }
  41. if(a<=0)
  42. {
  43. return -1;
  44. }
  45. }
  46. bool check_otr(const point &b1,const point &b2,const point &e1,const point &e2)
  47. {
  48.  
  49. vect l2,r2,c2,l,r,c;
  50. l=v(b1,b2);
  51. r=v(b1,e2);
  52. c=v(b1,e1);
  53. l2=v(b2,e1);
  54. r2=v(b2,b1);
  55. c2=v(b2,e2);
  56. if((sign(vector_proizv(c,l))*sign(vector_proizv(c,r))<=0)&&(sign(vector_proizv(c2,l2))*sign(vector_proizv(c2,r2))<=0))
  57. {
  58. return true;
  59. }
  60.  
  61. return false;
  62.  
  63. }
  64. long long cross(const point &b1,const point &b2,const point &e1,const point &e2)
  65. {
  66. vect l2,r2,c2,l,r,c;
  67. l=v(b1,b2);
  68. r=v(b1,e2);
  69. c=v(b1,e1);
  70. l2=v(b2,e1);
  71. r2=v(b2,b1);
  72. c2=v(b2,e2);
  73.  
  74.  
  75. return vector_proizv(c,c2);
  76. }
  77. long long a,b;
  78. int otr,as,f,cur,cur2,cur3,cur4,flag;
  79. vect p,q;
  80. point ta[3],tb[3],w;
  81.  
  82. int main()
  83. {
  84. //cin>>ta[1].x>>ta[1].y>>ta[2].x>>ta[2].y>>tb[1].x>>tb[1].y>>tb[2].x>>tb[2].y;
  85. //cout<<check_otr(ta[1],tb[1],ta[2],tb[2]);
  86. //return 0;
  87. cin>>ta[1].x>>ta[1].y;
  88. cin>>a>>b;
  89. if((a==0)&&(b==0))
  90. {
  91. f=1;
  92. as=1;
  93. }
  94. if((a==0)||(b==0)&&(!((a==0)&&(b==0))))
  95. {
  96. otr=1;
  97. }
  98. ta[2].x=ta[1].x+a;
  99. ta[2].y=ta[1].y;
  100. ta[3].x=ta[1].x;
  101. ta[3].y=ta[1].y+b;
  102. cin>>tb[1].x>>tb[1].y;
  103. cin>>a>>b;
  104. if((a==0)&&(b==0)&&(f==1))
  105. {
  106. f=1;
  107. }
  108. else
  109. {
  110. f=0;
  111. }
  112. if((a==0)&&(b==0))
  113. {
  114. as=1;
  115. }
  116. if((a==0)||(b==0)&&(!((a==0)&&(b==0))))
  117. {
  118. otr=1;
  119. }
  120.  
  121.  
  122.  
  123. tb[2].x=tb[1].x+a;
  124. tb[2].y=tb[1].y;
  125. tb[3].x=tb[1].x;
  126. tb[3].y=tb[1].y+b;
  127. for(cur=1;cur<=3;cur++)
  128. {
  129. for(cur2=1;cur2<=3;cur2++)
  130. {
  131. if(cmp(ta[cur],tb[cur2]))
  132. {
  133. cout<<"YES"<<endl;
  134. return 0;
  135. }
  136. }
  137.  
  138. }
  139. for(cur=1;cur<=3;cur++)
  140. {
  141. for(cur2=1;cur2<=3;cur2++)
  142. {
  143. for(cur3=1;cur3<=3;cur3++)
  144. {
  145. for(cur4=1;cur4<=3;cur4++)
  146. {
  147. if((cur!=cur3)&&(cur2!=cur4)&&(check_otr(ta[cur],tb[cur2],ta[cur3],tb[cur4])))
  148. {
  149. cout<<"YES"<<endl;
  150. return 0;
  151. }
  152. }
  153. }
  154. }
  155. }
  156. ta[4]=ta[1];
  157. tb[4]=tb[1];
  158.  
  159. for(cur=1;cur<=3;cur++)
  160. {
  161.  
  162. if((f==0)&&(sign(cross(ta[1],ta[1],tb[cur],ta[2]))==sign(cross(ta[2],ta[2],tb[cur],ta[3])))&&(sign(cross(ta[1],ta[1],tb[cur],ta[2]))==sign(cross(ta[3],ta[3],tb[cur],ta[1]))))
  163. {
  164. cout<<"YES"<<endl;
  165. return 0;
  166. }
  167.  
  168. }
  169. for(cur=1;cur<=3;cur++)
  170. {
  171.  
  172. if((!((otr==1)||(f==1)))&&(f==0)&&
  173. (sign(cross(tb[1],tb[1],ta[cur],tb[2]))==sign(cross(tb[2],tb[2],ta[cur],tb[3])))&&(sign(cross(tb[1],tb[1],ta[cur],tb[2]))==sign(cross(tb[3],tb[3],ta[cur],tb[1]))))
  174. {
  175. cout<<"YES"<<endl;
  176. return 0;
  177. }
  178.  
  179. }
  180.  
  181. cout<<"NO"<<endl;
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement