fork download
  1. #include <iostream>
  2. #include <math.h>
  3. #include <iomanip>
  4.  
  5.  
  6.  
  7. const double PI = 3.14159265;
  8.  
  9. template<typename Type>
  10. auto bezwzgledna(Type var)
  11. {
  12. if (var < 0)
  13. return -var;
  14. else
  15. return var;
  16. }
  17.  
  18.  
  19. class Wspolrzedna
  20. {
  21. private:
  22.  
  23. public:
  24. double x;
  25. double y;
  26. Wspolrzedna() {}
  27. Wspolrzedna(double a, double b) : x(a), y(b) {}
  28. bool operator==(Wspolrzedna & druga)
  29. {
  30. if (x == druga.x && y == druga.y)
  31. return true;
  32. else
  33. return false;
  34. }
  35. };
  36.  
  37. class Bierka
  38. {
  39. private:
  40. bool minus(double a) { if (a < 0) return true; else return false; }
  41. bool getLineIntersection(double p0_x, double p0_y, double p1_x, double p1_y, double p2_x, double p2_y, double p3_x, double p3_y)
  42. {
  43. double s1_x, s1_y, s2_x, s2_y;
  44. s1_x = p1_x - p0_x;
  45. s1_y = p1_y - p0_y;
  46. s2_x = p3_x - p2_x;
  47. s2_y = p3_y - p2_y;
  48. double s, t;
  49. s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / (-s2_x * s1_y + s1_x * s2_y);
  50. t = (s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / (-s2_x * s1_y + s1_x * s2_y);
  51.  
  52.  
  53.  
  54. if (s > 0 && s < 1 && t > 0 && t < 1)
  55. return true;
  56. else
  57. return false;
  58.  
  59. }
  60.  
  61. public:
  62. Wspolrzedna pierwsza;
  63. Wspolrzedna druga;
  64. Bierka() {}
  65. Bierka(double x1, double y1, double x2, double y2) : pierwsza(x1, y1), druga(x1, y1) {}
  66. bool null() {
  67. if (pierwsza == druga)
  68. return true;
  69. else
  70. return false;
  71. }
  72. bool L(Bierka & second);
  73. bool X(Bierka & second)
  74. {
  75. if (null() || second.null())
  76. return false;
  77. else
  78. return getLineIntersection(pierwsza.x, pierwsza.y, druga.x, druga.y, second.pierwsza.x, second.pierwsza.y, second.druga.x, second.druga.y);
  79. }
  80. bool V(Bierka & second);
  81. bool koniec_styczny(Bierka & second);
  82.  
  83.  
  84. // Metody sprawdzające czy funkcja jest stała i jaka konkretnie
  85. bool stala() { if (pierwsza.x == druga.x || pierwsza.y == druga.y) return true; else return false; }
  86. bool stala_x() { if (pierwsza.x == druga.x) return true; else return false; }
  87. bool stala_y() { if (pierwsza.y == druga.y) return true; else return false; }
  88. };
  89.  
  90. bool Bierka::koniec_styczny(Bierka & second)
  91. {
  92. if (
  93. ((druga == second.druga) && !(pierwsza == second.pierwsza)) ||
  94. ((druga == second.pierwsza) && !(pierwsza == second.druga)) ||
  95. (!(druga == second.druga) && (pierwsza == second.pierwsza)) ||
  96. (!(druga == second.pierwsza) && (pierwsza == second.druga))
  97. )
  98. return true;
  99. else
  100. return false;
  101. }
  102.  
  103. bool Bierka::L(Bierka & second)
  104. {
  105. if (null() || second.null())
  106. return false;
  107. else if (koniec_styczny(second) && !stala() && !second.stala())
  108. {
  109. double a1, a2;
  110.  
  111. if (druga.x != pierwsza.x)
  112. a1 = (druga.y - pierwsza.y) / (druga.x - pierwsza.x);
  113. else
  114. a1 = 0;
  115. if (second.druga.x != second.pierwsza.x)
  116. a2 = (second.druga.y - second.pierwsza.y) / (second.druga.x - second.pierwsza.x);
  117. else
  118. a2 = 0;
  119.  
  120. if (a1*a2 == -1)
  121. return true;
  122. else return false;
  123. }
  124. else if (koniec_styczny(second) && ((stala_x() && second.stala_y()) || (stala_y() && second.stala_x())))
  125. return true;
  126. else
  127. return false;
  128.  
  129. }
  130.  
  131.  
  132.  
  133. bool Bierka::V(Bierka & second)
  134. {
  135. if (null() || second.null())
  136. return false;
  137. else if (koniec_styczny(second))
  138. {
  139. double x_vektora, y_vektora, second_x_vektora, second_y_vektora;
  140.  
  141. // Warunki określające początek wektorów (tak aby oba wektory miały początek w punkcie wspólnym
  142. if (druga == second.druga)
  143. {
  144. x_vektora = pierwsza.x - druga.x;
  145. y_vektora = pierwsza.y - druga.y;
  146. second_x_vektora = second.pierwsza.x - second.druga.x;
  147. second_y_vektora = second.pierwsza.y - second.druga.y;
  148. }
  149. else if (druga == second.pierwsza)
  150. {
  151. x_vektora = pierwsza.x - druga.x;
  152. y_vektora = pierwsza.y - druga.y;
  153. second_x_vektora = second.druga.x - second.pierwsza.x;
  154. second_y_vektora = second.druga.y - second.pierwsza.y;
  155. }
  156. else if (pierwsza == second.druga)
  157. {
  158. x_vektora = druga.x - pierwsza.x;
  159. y_vektora = druga.y - pierwsza.y;
  160. second_x_vektora = second.pierwsza.x - second.druga.x;
  161. second_y_vektora = second.pierwsza.y - second.druga.y;
  162. }
  163. else if (pierwsza == second.pierwsza)
  164. {
  165. x_vektora = druga.x - pierwsza.x;
  166. y_vektora = druga.y - pierwsza.y;
  167. second_x_vektora = second.druga.x - second.pierwsza.x;
  168. second_y_vektora = second.druga.y - second.pierwsza.y;
  169. }
  170.  
  171.  
  172.  
  173. double angle;
  174.  
  175.  
  176. double kat_main = atan2(y_vektora, x_vektora) * 180 / PI;
  177. double kat_second = atan2(second_y_vektora, second_x_vektora) * 180 / PI;
  178.  
  179. // warunki sprawdzające czy atan dało wynik ujemny
  180. if (kat_main < 0)
  181. kat_main = 360 - bezwzgledna(kat_main);
  182. if (kat_second < 0)
  183. kat_second = 360 - bezwzgledna(kat_second);
  184.  
  185. angle = bezwzgledna(kat_main - kat_second);
  186.  
  187. if (angle < 90 && angle > 0)
  188. return true;
  189. else
  190. return false;
  191. }
  192. else
  193. return false;
  194. }
  195.  
  196.  
  197.  
  198. int main()
  199. {
  200. int ile;
  201. std::cin >> ile;
  202. Bierka * bierki = new Bierka[ile * 2];
  203. double x1, y1, x2, y2;
  204.  
  205. for (int i = 0; i < ile * 2; i++)
  206. {
  207. std::cin >> x1 >> y1 >> x2 >> y2;
  208. bierki[i].pierwsza.x = x1;
  209. bierki[i].pierwsza.y = y1;
  210. bierki[i].druga.x = x2;
  211. bierki[i].druga.y = y2;
  212. }
  213. char * liczby_rzymskie = new char[ile];
  214. for (int i = 0, g = 0; i < ile * 2; i += 2, g++)
  215. {
  216. if (bierki[i].L(bierki[i + 1]))
  217. liczby_rzymskie[g] = 'L';
  218.  
  219. else if (bierki[i].X(bierki[i + 1]))
  220. liczby_rzymskie[g] = 'X';
  221.  
  222. else if (bierki[i].V(bierki[i + 1]))
  223. liczby_rzymskie[g] = 'V';
  224.  
  225. else
  226. liczby_rzymskie[g] = '-';
  227. }
  228.  
  229. long double iloczyn = 1;
  230. for (int i = 0; i < ile; i++)
  231. {
  232. switch (liczby_rzymskie[i])
  233. {
  234. case 'L':
  235. printf("L\n");
  236. iloczyn *= 50;
  237. break;
  238. case 'X':
  239. printf("X\n");
  240. iloczyn *= 10;
  241. break;
  242. case 'V':
  243. printf("V\n");
  244. iloczyn *= 5;
  245. break;
  246. case '-':
  247. printf("-\n");
  248. }
  249. }
  250.  
  251. std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(0) << iloczyn;
  252. delete[] liczby_rzymskie;
  253. delete[] bierki;
  254.  
  255. return 0;
  256. }
Success #stdin #stdout 0s 3464KB
stdin
1
0 0 0 0
0 0 0 0
stdout
-
1