Skip to content

Commit 3b3ba0a

Browse files
committed
2162,p5,Geometry,solve(cheating)(00:52:29)
1 parent 476eda9 commit 3b3ba0a

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const [[N],[sx,sy],...points] = require('fs').readFileSync(process.platform === 'linux' ? '/dev/stdin' : require('path').resolve(__dirname,'../../../testcase.txt'))
2+
.toString()
3+
.trim()
4+
.split('\n')
5+
.map(row=>row.split(' ').map(Number))
6+
7+
function outerProduct(v1,v2){
8+
return v1[0]*v2[1] - v1[1]*v2[0]
9+
}
10+
11+
let result = 0
12+
points.unshift([sx,sy])
13+
points.push([sx,sy])
14+
for(let i=0;i<points.length-1;i++){
15+
const v1 = [points[i][0], points[i][1]]
16+
const v2 = [points[i+1][0], points[i+1][1]]
17+
result += outerProduct(v1,v2)
18+
}
19+
console.log(Math.abs(result/2).toFixed(1))
20+
21+
// 00:09:50 틀렸습니다(2%) -> 선을 긋는 순서대로 좌표를 찍어야함 -> 순서대로 주어짐 -> toFixed 수정
22+
// 00:27:16 틀렸습니다(2%) -> 수동으로 반올림 구현
23+
// 00:52:29 맞았습니다(책 참고)

0 commit comments

Comments
 (0)