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
- C++
- 비재귀셰그먼트
- 데이터베이스 배움터
- 언리얼 커스텀 플러그인
- oracle
- 실습
- 1759번
- 트랜잭션 관리
- 1967번
- objtofbx
- 오손데이터읽기
- UActor
- UnrealMP
- hackerank
- 언리얼 플러그인
- 백준
- SQL
- 민겸수
- FBX
- 의미와 무의미의 경계에서
- 2단계로킹
- Security
- 백준 1253번
- command not found
- OS
- Linux
- 1253번
- 5639
- 셰그먼트트리
- Unreal
Archives
- Today
- Total
fatalite
CCW - 백준 11758번 본문
Problem
골드 5 기하학 문제
잘 알려진 문제여서 외적을 사용하면 되는 것을 알고 있지만,
내적을 사용해도 되지 않을까? 라고 생각했다.
그러나 내적을 사용하면, cos 값이 90도 일때와 270(-90)도 일 때 모두 0 이기 때문에
CCW인지 CW인지 판별하기 어렵다는 것을 유추할 수 있다.
따라서 외적을 사용해야한다.
궁금하지만 일단 나중에 알아볼게 있는데
외적과 행렬식의 관계를 알아야할 필요가 있어보인다.
Solution
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <queue>
using namespace std;
int Cross(pair<int, int> p1, pair<int, int> p2) {
int ScalarOfOuterVector =
p1.first * p2.second - p2.first * p1.second;
if (ScalarOfOuterVector < 0) {
return 1;
}
else if (ScalarOfOuterVector > 0) {
return -1;
}
else {
return 0;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int FirstX, FirstY, SecondX, SecondY, ThirdX, ThirdY;
cin >> FirstX >> FirstY >> SecondX >> SecondY >> ThirdX >> ThirdY;
pair<int, int> FirstVector({ ThirdX - SecondX, ThirdY - SecondY });
pair<int, int> SecondVector({ SecondX - FirstX, SecondY - FirstY });
cout << Cross(FirstVector, SecondVector);
}'코딩 인터뷰 > C++' 카테고리의 다른 글
| 치킨 배달 / 15686번 백준 (4) | 2023.09.03 |
|---|---|
| N-Queens / 9663번 백준 🌋🌋🌋🌋 (0) | 2023.08.31 |
| 이분 그래프 - 백준 1707 (0) | 2023.05.22 |
| ☆ 용액 - 백준 2467 (0) | 2023.04.11 |
| ☆ 스티커 - 백준 9465 (1) | 2023.04.09 |