Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- softeer
- 2294
- Programmers
- RootMotion
- TObjectPtr
- 팰린드롬 만들기
- 1563
- UE5
- NRVO
- C++
- UnrealEngine5
- directx
- 백준
- DirectX11
- GeeksForGeeks
- algorithm
- const
- C
- 티스토리챌린지
- baekjoon
- Unreal Engine5
- 프로그래머스
- Frustum
- 오블완
- UnrealEngine4
- 줄 세우기
- winapi
- IFileDialog
- 언리얼엔진5
- RVO
Archives
- Today
- Total
Game Develop
[Algorithm]Baekjoon 11758번 :: CCW 본문
https://www.acmicpc.net/problem/11758
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <functional>
#include <sstream>
#include <memory.h>
#include <deque>
#include <set>
#include <unordered_map>
#include <stack>
#include <numeric>
#include <climits>
#include <bitset>
#include <cmath>
#include <mutex>
using namespace std;
struct Vector
{
int x = 0;
int y = 0;
int z = 0;
};
Vector Cross(const Vector& v1, const Vector& v2)
{
Vector result =
{
v1.y * v2.z - v1.z * v2.y,
v1.z * v2.x - v1.x * v2.z,
v1.x * v2.y - v1.y * v2.x
};
return result;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
Vector v1 = { x2 - x1, y2 - y1, 0 };
Vector v2 = { x3 - x2, y3 - y2, 0 };
int dir = Cross(v1, v2).z;
if (dir < 0)
{
cout << -1;
}
else if (dir == 0)
{
cout << 0;
}
else
{
cout << 1;
}
return 0;
}
|
cs |
세 점이 주어지고 각 점을 순서대로 이었을 때, 시계방향인지, 반시계방향인지(CCW인지), 그냥 일직선인지를 판별해야하는 문제이다.
외적을 통해 쉽게 구할 수 있기 때문에, 외적을 구하는 공식을 알고있어야 풀 수 있다.
문제에서는 2차원좌표라서 위의 코드처럼 할 필요는 없다만, 그냥 다시 숙지할 겸 3차원이라 가정하고 외적코드를 작성했다.
'Algorithm > Baekjoon' 카테고리의 다른 글
[Algorithm]Baekjoon 14621번 :: 나만 안되는 연애 (1) | 2025.03.19 |
---|---|
[Algorithm]Baekjoon 6497번 :: 전력난 (0) | 2025.03.19 |
[Algorithm]Baekjoon 3151번 :: 합이 0 (0) | 2025.03.19 |
[Algorithm]Baekjoon 17609번 :: 회문 (0) | 2025.03.18 |
[Algorithm]Baekjoon 2461번 :: 대표 선수 (0) | 2025.03.17 |