티스토리 뷰

https://www.acmicpc.net/problem/20157

 

20157번: 화살을 쏘자!

호준이는 요즘 활 쏘기에 푹 빠져 있다. 열심히 활 쏘기를 연습하던 호준이는 쏠 때 마다 10점이 나오는 경지에 이르렀다. 이렇다 보니 한 방향으로 있는 과녁에 쏘는 것에 실증을 느낀 호준이는

www.acmicpc.net

const [N, ...targets] = require('fs')
	.readFileSync('./dev/stdin')
	.toString()
	.trim()
	.split('\n')
	.map((v) => v.split(' ').map(Number));
const getGCD = (num1, num2) => {
	while (num2 > 0) {
		let r = num1 % num2;
		num1 = num2;
		num2 = r;
	}
	return num1;
};

const leans = new Map();

targets.forEach((v) => {
	[x, y] = v;

	let lean;

	if (x == 0 && y > 0) {
		lean = '+0';
	} else if (x == 0 && y < 0) {
		lean = '-0';
	} else if (x < 0 && y == 0) {
		lean = '-Infinity';
	} else if (x > 0 && y == 0) {
		lean = 'Infinity';
	} else {
		const gcd = getGCD(Math.abs(x), Math.abs(y));
		lean = `${x / gcd}/${y / gcd}`;
	}

	if (leans.has(lean)) {
		const cnt = leans.get(lean);
		leans.set(lean, cnt + 1);
	} else {
		leans.set(lean, 1);
	}
});
const max = Math.max(...leans.values());
console.log(max);
728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/09   »
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
글 보관함