Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. #include <fstream>
  2.  
  3.  
  4. using namespace std;
  5. ifstream cin ("drept.in");
  6. ofstream cout("drept.out");
  7.  
  8. struct punct
  9. {
  10. int x;
  11. int y;
  12. };
  13.  
  14. punct v[210];
  15.  
  16. int punctPeSegment(int i, int j)
  17. {
  18. if (v[i].x >= min(v[j].x, v[j+1].x) && v[i].x <= max(v[j].x, v[j+1].x))
  19. if (v[i].y >= min(v[j].y, v[j+1].y) && v[i].y <= max(v[j].y, v[j+1].y))
  20. return 1;
  21. return 0;
  22. }
  23.  
  24. int intersectieSegmente(punct a, punct b, punct c, punct d)
  25. {
  26. punct aux;
  27. if (a.x > b.x)
  28. {
  29. aux = a;
  30. a = b;
  31. b = aux;
  32. }
  33. if (c.y > d.y)
  34. {
  35. aux = c;
  36. c = d;
  37. d = aux;
  38. }
  39. if ((d.y > a.y) && (c.y < a.y) )
  40. {
  41. if ((c.x < b.x) && (c.x > a.x))
  42. {
  43. return 1;
  44. }
  45. }
  46. return 0;
  47. }
  48.  
  49. int main ()
  50. {
  51. int C, t, n, xmin, xmax, ymin, ymax, i, d, j, k;
  52. int poligon, aria, jos, stanga;
  53. cin>>C>>t;
  54.  
  55. for (; t--;)
  56. {
  57. cin>>n;
  58. xmin = 0;
  59. ymin = 0;
  60. ymax = 0;
  61. xmax = 0;
  62. v[0].x = 0;
  63. v[0].y = 0;
  64. for (i=1; i<=n; i++)
  65. {
  66. cin>>d;
  67. if (i%2 == 1)
  68. {
  69. v[i].x = v[i-1].x + d;
  70. v[i].y = v[i-1].y;
  71. }
  72. else
  73. {
  74. v[i].x = v[i-1].x;
  75. v[i].y = v[i-1].y + d;
  76. }
  77. xmin = min(xmin, v[i].x);
  78. xmax = max(xmax, v[i].x);
  79. ymin = min(ymin, v[i].y);
  80. ymax = max(ymax, v[i].y);
  81. }
  82.  
  83. poligon = 1;
  84. if (v[n].x != 0 || v[n].y != 0)
  85. poligon = 0;
  86.  
  87. for (i=0; i<n-1; i++)
  88. {
  89. for (j=i+2; j<n; j++)
  90. {
  91. if (i == 0 && j == n-1)
  92. continue;
  93.  
  94. if (i%2 == j%2)
  95. {
  96. if (punctPeSegment(i, j))
  97. poligon = 0;
  98. if (punctPeSegment(i+1, j))
  99. poligon = 0;
  100. if (punctPeSegment(j, i))
  101. poligon = 0;
  102. if (punctPeSegment(j+1, i))
  103. poligon = 0;
  104. }
  105. else
  106. {
  107. if (i%2 == 0)
  108. {
  109.  
  110. if (intersectieSegmente(v[i], v[i+1], v[j], v[j+1]))
  111. poligon = 0;
  112. }
  113. else
  114. {
  115. if (intersectieSegmente(v[j], v[j+1], v[i], v[i+1]))
  116. poligon = 0;
  117. }
  118. }
  119.  
  120.  
  121. }
  122.  
  123. }
  124. if (C==2)
  125. {
  126. /* aria = 0;
  127. for (i=xmin+1; i<=xmax; i++)
  128. for (j=ymin+1; j<=ymax; j++)
  129. {
  130.  
  131.  
  132. }
  133.  
  134.  
  135. */
  136. }
  137. if (C == 1)
  138. {
  139. cout<<poligon<<" ";
  140. }
  141. else
  142. {
  143.  
  144. cout<<aria<<" ";
  145. }
  146.  
  147. }
  148.  
  149. return 0;
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement