BOJ 11758: CCW

https://www.acmicpc.net/problem/11758

  • 3월동안 210문제 풀기 (2/210)
  • CCW가 외적인것을 배우는 문제. 그리고 기하 알고리즘의 기본인 Vector 클래스 디자인을 배우는 문제.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <bits/stdc++.h>
using namespace std;

const double EPS = 1e-9;
struct Vector {
  double x, y;

  Vector(int x, int y) {
    this->x = x, this->y = y;
  }

  Vector(const Vector& v1) {
    x = v1.x, y =v1.y;
  }

  Vector(const Vector& v1, const Vector& v2) {
    x = v2.x - v1.x, y = v2.y - v1.y;
  }

  Vector& operator+=(const Vector &other) {
    x += other.x;
    y += other.y;
    return *this;
  }

  Vector& operator-=(const Vector &other) {
    x -= other.x;
    y -= other.y;
    return *this;
  }

  Vector& operator*=(const double C) {
    x *= C;
    y *= C;
    return *this;
  }

  Vector& operator/=(const double C) {
    x /= C;
    y /= C;
    return *this;
  }

  Vector operator+(const Vector &other) const {
    return Vector(*this) += other;
  }

  Vector operator-(const Vector &other) const {
    return Vector(*this) -= other;
  }

  Vector operator*(const double C) const {
    return Vector(*this) *= C;
  }

  Vector operator/(const double C) const {
    return Vector(*this) /= C;
  }
};

double cross(Vector v1, Vector v2) {
  return v1.x * v2.y - v1.y * v2.x;
}

double ccw(Vector va, Vector vb) {
  double v = cross(va, vb);
  if(abs(v) < EPS) return 0;
  if(v > 0) return 1;
  if(v < 0) return -1;
}

double ccw(Vector vr, Vector va, Vector vb) {
  return ccw(va - vr, vb - vr);
}

int main() {
  int x1, x2, x3, y1, y2, y3;
  cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
  Vector v1(x1,y1), v2(x2,y2), v3(x3,y3);
  cout << ccw(v2, v3, v1);
}