점 3개의 방향 알아내기 CCW, CW
2019. 10. 31. 00:22ㆍ알고리즘/암기
x, y 좌표평면에 점 3개가 있고, 넓이를 구함으로써 이어진 점들의 방향이 CW, CCW임을 알 수 있다
[참고] https://www.acmicpc.net/blog/view/27
참고문제: https://www.acmicpc.net/problem/11758
깃허브주소: https://github.com/surinoel/boj/blob/master/11758.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 삼각형의 면적이 최대 int 범위를 넘지 않으므로 자료형은 int로 해도 무방하다 */ | |
#include <iostream> | |
using namespace std; | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
long long x1, x2, x3, y1, y2, y3; | |
cin >> x1 >> y1; | |
cin >> x2 >> y2; | |
cin >> x3 >> y3; | |
long long s = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1); | |
if (s < 0) { | |
cout << -1 << '\n'; | |
} | |
else if (s == 0) { | |
cout << 0 << '\n'; | |
} | |
else { | |
cout << 1 << '\n'; | |
} | |
return 0; | |
} |