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 | 31 |
Tags
- 스코프
- 옵셔널체이닝
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- js 스코프
- emotion RSC
- 프로그래머스 문자열 압축
- js 거리두기 확인하기
- 자바스크립트 스코프
- app router emotion
- 구름톤 챌린지
- next13 emotion
- js
- suspense 동작원리
- 프로그래머스 거리두기 확인하기
- 자바스크립트 문자열 압축
- 카카오 코테
- 리액트쿼리 suspense
- js 문자열 압축
- 사용성 개선
- 구름톤
- 백준 2108 nodejs
- suspense 비동기
- 구름톤 챌린지 회고
- 백준 1339번 자바스크립트
- 백준 2108 자바스크립트
- suspense react-query
- emtion app router
- suspense 병목현상
- 백준 1339번 js
- 백준 1339번 nodejs
Archives
- Today
- Total
Lennon FE
[백준 11758번] CCW - 자바스크립트(nodejs) 본문
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
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input = [];
rl.on('line', function (line) {
input.push(line);
if (input.length === 3) {
rl.close();
}
}).on('close', function () {
const [x1, y1, x2, y2, x3, y3] = input.reduce((prev, cur) => {
for (let i of cur.split(' ')) {
prev.push(+i);
}
return prev;
}, []);
const external1 = x1 * y2 + x2 * y3 + x3 * y1;
const external2 = y1 * x2 + y2 * x3 + y3 * x1;
if (external1 > external2) {
console.log(1);
} else if (external1 < external2) {
console.log(-1);
} else {
console.log(0);
}
});
CCW알고리즘을 이용해 푸는 문제이다.
각 좌표에 대해 방향관계를 구해야한다.
CCW 함수의 리턴값은 위 코드에서 external1 - external2 이다.
이게 음수면 시계방향, 양수면 반시계방향이며, 0이면 세 점이 일직선 상에 놓인다.
그냥 값을 구하려면 기울기 및 방향까지 신경써서 많은 조건을 걸고 풀어야하지만, CCW 알고리즘을 이용하면
쉽게 풀 수 있다.
728x90
반응형
Comments