Problem Solving/BOJ

[BOJ] 11758 : CCW

shyram 2019. 1. 4. 00:59

기하 알고리즘의 시작에는 CCW가 있다.


외적을 이용하는 알고리즘인데, 추후에 포스팅 해봐야겠다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
#define pp pair<intint>
using namespace std;
 
int ccw(pp a, pp b, pp c) {
    int temp = a.first*b.second + b.first*c.second + c.first*a.second;
    temp -= a.second*b.first + b.second*c.first + c.second*a.first;
    if (temp > 0return 1;
    else if (temp < 0return -1;
    else return 0;
}
 
pp xy[3];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    for (int i = 0; i < 3; i++) {
        cin >> xy[i].first >> xy[i].second;
    }
    cout << ccw(xy[0], xy[1], xy[2]);
}
cs