상세 컨텐츠

본문 제목

11758번: CCW - CCW

알고리즘/baekjoon

by oVeron 2023. 1. 23. 10:15

본문

728x90
반응형

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

 

11758번: CCW

첫째 줄에 P1의 (x1, y1), 둘째 줄에 P2의 (x2, y2), 셋째 줄에 P3의 (x3, y3)가 주어진다. (-10,000 ≤ x1, y1, x2, y2, x3, y3 ≤ 10,000) 모든 좌표는 정수이다. P1, P2, P3의 좌표는 서로 다르다.

www.acmicpc.net

#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <string>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int x1, y1, x2, y2, x3, y3;
	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

	int p2p1x = x1 - x2;
	int p2p1y = y1 - y2;
	int p2p3x = x3 - x2;
	int p2p3y = y3 - y2;

	int ccw = p2p1x * p2p3y - p2p1y * p2p3x;
	if (ccw > 0) cout << -1; //벡터의 외적값이 0보다 크면 시계방향
	else if (ccw < 0) cout << 1; //작으면 반시계방향
	else cout << 0; //0이면 일직선
}
728x90
반응형

관련글 더보기

댓글 영역