Advertisement
a53

intersectiesegmente

a53
Mar 12th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <fstream>
  2. #include <stdlib.h>
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin ("intersectiesegmente.in");
  7. ofstream fout("intersectiesegmente.out");
  8.  
  9. int X1, Y1, X2, Y2, X3, Y3, X4, Y4;
  10. int d1, d2, d3, d4;
  11.  
  12. int det(int X1, int Y1, int X2, int Y2, int X3, int Y3) {
  13. return (X2-X1)*(Y3-Y1) - (X3-X1)*(Y2-Y1);
  14. }
  15.  
  16. int punctPeSegment(int x1, int y1, int x2, int y2, int x3, int y3) {
  17. int d = det(x1, y1, x2, y2, x3, y3);
  18. if (d!=0)
  19. return 0;
  20. if (x1 == x3 && y1 == y3)
  21. return 1;
  22. if (x2 == x3 && y2 == y3)
  23. return 1;
  24. if ((x3-x1) * (x3-x2) < 0 || (y3-y1) * (y3-y2) < 0)
  25. return 1;
  26. else
  27. return 0;
  28. }
  29.  
  30.  
  31. void msgAndOut(char *msg) {
  32. fout<<msg;
  33. exit(0);
  34. }
  35.  
  36. int main() {
  37. fin>>X1>>Y1>>X2>>Y2>>X3>>Y3>>X4>>Y4;
  38.  
  39. if (punctPeSegment(X1, Y1, X2, Y2, X3, Y3)) {
  40. msgAndOut("DA\n");
  41. }
  42.  
  43. if (punctPeSegment(X1, Y1, X2, Y2, X4, Y4)) {
  44. msgAndOut("DA\n");
  45. }
  46.  
  47. if (punctPeSegment(X3, Y3, X4, Y4, X1, Y1)) {
  48. msgAndOut("DA\n");
  49. }
  50.  
  51. if (punctPeSegment(X3, Y3, X4, Y4, X2, Y2)) {
  52. msgAndOut("DA\n");
  53. }
  54.  
  55. d1 = det(X3, Y3, X4, Y4, X1, Y1);
  56. d2 = det(X3, Y3, X4, Y4, X2, Y2);
  57. d3 = det(X1, Y1, X2, Y2, X3, Y3);
  58. d4 = det(X1, Y1, X2, Y2, X4, Y4);
  59.  
  60. if (d1 * d2 < 0 && d3 * d4 < 0)
  61. msgAndOut("DA\n");
  62. else
  63. msgAndOut("NU\n");
  64.  
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement