11758. CCW

욥·2026년 9월 17일

백준 알고리즘

목록 보기
352/353

CCW

  • 1) 신발끈 공식을 외우자.
  • 2) RES 가 음수면 시계 방향, 양수면 반시계 방향, 0이면 일직선
  • 3) 구한 res값의 절반은 삼각형의 넓이다.

정답 코드

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;



int main()
{
	
	// 신발 끈 공식 
	// 음수면 시계방향
	// 0이면 일직선, 
	// 양수면 반시계 방향.

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

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

	int res = (x1 * y2 + x2 * y3 + x3 * y1) - (y1 * x2 + y2 * x3 + y3 * x1);

	if (res < 0)
		cout << -1;
	else if (res == 0)
		cout << 0;
	else
		cout << 1;


	return 0;
}
profile
🔥🔥🔥

0개의 댓글