Algorithm/hackerrank
-
[hackerrank] Organizing Containers of BallsAlgorithm/hackerrank 2020. 10. 24. 00:23
www.hackerrank.com/challenges/organizing-containers-of-balls/problem Organizing Containers of Balls | HackerRank Determine if David can perform some sequence of swap operations such that each container holds one distinct type of ball. www.hackerrank.com 문제풀이 1. 각 컨테이너에 같은 한 가지 타입의 볼만 존재하도록 만들 수 있는가를 묻는 문제이다. 2. 처음에는 swap을 이용하여 현재 컨테이너의 볼만 존재하도록 실행했으나, 볼의 개수가 10^9를 차지하는 경우가 존재하여 너무 큰 시간 초과가 날 것 같..
-
[hackerrank] Ema's Supercomputer(c++)Algorithm/hackerrank 2020. 10. 22. 23:47
www.hackerrank.com/challenges/two-pluses/problem Ema's Supercomputer | HackerRank Determine the product of the areas of two pluses on a grid. www.hackerrank.com 풀이과정 1. 주어진 그리드 맵에서 그림과 같이 크로스를 2개 그려서 두 크로스의 곱의 최댓값을 구하는 문제이다. 2. BFS를 이용하여 크로스를 그려주었다. 4방향 모두 이동 할 수 있는지 체크를 하고, 한 방향이라도 갈 수 없다면 취소하고 리턴 시켰다. 3. 모든 경우의 수를 체크해줘야 한다. * 현재 위치에서 최대로 9칸 크로스를 그릴 수 있어도, 5칸 크로스의 경우도 따지고 들어가야한다. (곱의 최댓값이다.) 소스..
-
[hackerrank] Climbing the Leaderboard(c++)Algorithm/hackerrank 2020. 10. 21. 23:21
www.hackerrank.com/challenges/climbing-the-leaderboard/problem Climbing the Leaderboard | HackerRank Help Alice track her progress toward the top of the leaderboard! www.hackerrank.com 풀이과정 1. ranked는 내림차순(4,3,2,1)으로 정렬되어 있으며, player는 오름차순(1,2,3,4)이다. 2. 중복값은 같은 등수로 처리되기 때문에 원소에서 제거하고 시작하였다. 3. 꼴등부터 시작하여 현재 Player의 점수보다 현재 랭킹점수가 더 크면 반복문을 종료하여 현재 랭크를 정해준다. 4. player는 오름차순이므로 다음 플레이어는 현재 플레이어보다 등..
-
[HackerRank] Extra Long Factorials(c++)Algorithm/hackerrank 2020. 10. 20. 23:34
www.hackerrank.com/challenges/extra-long-factorials/problem Extra Long Factorials | HackerRank Calculate a very large factorial that doesn't fit in the conventional numeric data types. www.hackerrank.com [문제풀이] 1 ~ 100 사이의 N을 입력받아 해당 N의 팩토리얼 값을 구하는 문제이다. N이 30만 넘어도 c++ 64bit unsigned long long의 최댓값을 넘게 된다. 따라서 배열을 이용하여 각 자리수로 생각하고 접근하여 문제를 해결하였다. [소스코드] 더보기 void extraLongFactorials(int n) { int ..