fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. struct Point {
  8. long long x, y;
  9. bool operator<(const Point& other) const {
  10. if (x != other.x) return x < other.x;
  11. return y < other.y;
  12. }
  13. bool operator==(const Point& other) const {
  14. return x == other.x && y == other.y;
  15. }
  16. };
  17.  
  18. // Kvadrat rastojanja izmedu dve tacke
  19. long long distSq(Point p1, Point p2) {
  20. return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
  21. }
  22.  
  23. int main() {
  24. vector<Point> p(4);
  25. for (int i = 0; i < 4; i++) {
  26. if (!(cin >> p[i].x >> p[i].y)) return 0;
  27. }
  28.  
  29. // Sortiranjem dobijamo fiksni raspored temena
  30. sort(p.begin(), p.end());
  31.  
  32. // Provera da li su tacke razlicite (romb ne može biti tacka ili duž)
  33. for (int i = 0; i < 3; i++) {
  34. if (p[i] == p[i+1]) {
  35. cout << "NE" << endl;
  36. return 0;
  37. }
  38. }
  39.  
  40. // Kod sortiranih tacaka, dijagonale su (p0, p3) i (p1, p2)
  41. // 1. Uslov: Dijagonale se polove (središta su ista)
  42. bool isParallelogram = (p[0].x + p[3].x == p[1].x + p[2].x) &&
  43. (p[0].y + p[3].y == p[1].y + p[2].y);
  44.  
  45. // 2. Uslov: Sve stranice su jednake (romb)
  46. // Stranice su p0-p1, p1-p3, p3-p2, p2-p0
  47. bool allSidesEqual = (distSq(p[0], p[1]) == distSq(p[1], p[3])) &&
  48. (distSq(p[1], p[3]) == distSq(p[3], p[2])) &&
  49. (distSq(p[3], p[2]) == distSq(p[2], p[0]));
  50.  
  51. // Dodatna provera: Površina ne sme biti nula (tacke nisu kolinearne)
  52. // Vektorski proizvod (p1-p0) i (p2-p0)
  53. long long area2 = abs((p[1].x - p[0].x) * (p[2].y - p[0].y) -
  54. (p[1].y - p[0].y) * (p[2].x - p[0].x));
  55.  
  56. if (isParallelogram && allSidesEqual && area2 > 0) {
  57. cout << "DA" << endl;
  58. } else {
  59. cout << "NE" << endl;
  60. }
  61.  
  62. return 0;
  63. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty