백준/기하

백준 11758 c++ -PlusUltraCode

PlusUltraCode 2024. 2. 15. 13:44

CCW알고리즘을 알고 있으면 쉽게 풀수 있는 문제이다.

 

/* x1 x2 x3 x1*/
/* y1 y2 y3 y1*/ 

 

CCW알고리즘은 
이런식으로 대각선끼리 곱해주고 빼주면 된다.

 

[소스코드]

#include <iostream>
#include <vector>
#include <cstring>
#include <string.h>
#include<cmath>
#include<climits>
using namespace std;

int main(void) {
	int x1, x2, x3, y1, y2, y3;

	/* x1 x2 x3 x1*/
	/* y1 y2 y3 y1*/

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

	int CCW = ( (x1 * y2) + (x2 * y3) + (x3 * y1) ) - ((x2* y1) + (x3 * y2) + (x1 * y3));
	if (CCW > 0)cout << 1;
	else if (CCW == 0) cout << 0;
	else cout << -1;
}