알고리즘
-
Left Rotation해커랭크(HackerRank) 2019. 3. 12. 08:36
1. 문제 2. 알고리즘 키워드 - 구현 * 문제 풀이 입력 으로 들어오는 배열에 요소를 왼쪽으로 d 만큼 ROTATION 하는 문제이며 d 입력 값에 따라 반복적으로 연산량이 증가 된다. 초기 접근은 d 만큼 반복문 내에서 swap 하도록 구현 하였으나 timeout 이 발생하여 다른 방법으로 접근 하기로 했음 문제에 주어진 조건에서 d 는 배열의 크기보다 작은 수로 입력 됨으로 아래와 같은 식을 세울 수 있다. 이동 될 위치 = ( 배열의 크기 - d + 현재 배열의 위치) % 배열의 크기 문제에서 주어진 예제 기준으로 대입 해 본다면 이동 될 위치는 아래 와 같다. index 0 일 때 = (5 - 4 + 0) % 5 이동 될 위치는 1 index 1 일 때 = (5 - 4 + 1) % 5 이동 될..
-
백준 1937번: 욕심쟁이 판다깊이우선탐색(DFS) 2019. 1. 20. 18:38
https://www.acmicpc.net/problem/1937 1937번: 욕심쟁이 판다 n*n의 크기의 대나무 숲이 있다. 욕심쟁이 판다는 어떤 지역에서 대나무를 먹기 시작한다. 그리고 그 곳의 대나무를 다 먹어 치우면 상, 하, 좌, 우 중 한 곳으로 이동을 한다. 그리고 또 그곳에서 대나무를 먹는다. 그런데 단 조건이 있다. 이 판다는 매우 욕심이 많아서 대나무를 먹고 자리를 옮기면 그 옮긴 지역에 그 전 지역보다 대나무가 많이 있어야 한다. 만약에 그런 지점이 없으면 이 판다는 불만을 가지고 단식 투쟁을 하다가 죽게 된다(-_-) 이 www.acmicpc.net 키워드 - DFS, 구현 Source #include #include #include #include #include #include..
-
백준 10984번: 내 학점을 구해줘구현(Implementation) 2019. 1. 14. 21:52
1. 문제 2. 알고리즘키워드 - 구현 3. 코드 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MAX_SIZE 100#define INF 0x7fffffff#define CENDL "\n"#define ll long long #define c_reverse(s) reverse(s.begin(), s.end())#define..
-
백준 1946번: 신입 사원그리디(Greedy) 2019. 1. 6. 14:15
https://www.acmicpc.net/problem/1946 1. 문제 정렬 후 second 값을 비교 second 값을 업데이트 2. 알고리즘키워드 - 그리디, 구현 3. 코드 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MAX_SIZE 100#define INF 0x7fffffff#define CEN..
-
백준 4307번: 개미그리디(Greedy) 2019. 1. 5. 21:02
https://www.acmicpc.net/problem/4307 1. 문제중간 위치에서 가장 가까운 위치가 가장 빨리 떨어지는 시간이 된다. 2. 알고리즘키워드 - 구현, 그리디 3. 코드 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MAX_SIZE 100#define INF 0x7fffffff#define..
-
백준 1267번: 핸드폰 요금구현(Implementation) 2018. 10. 22. 22:06
https://www.acmicpc.net/problem/1267 1. 문제 2. 알고리즘키워드 - 구현, 수학 3. 코드 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MAX_SIZE 100#define INF 0x7fffffff#define CENDL "\n"#define ll long long #d..
-
백준 2903번: 중앙 이동 알고리즘정수론(Number theory) 2018. 10. 21. 17:39
https://www.acmicpc.net/problem/2903 키워드 - 수학 Source #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MAX_SIZE 100 #define INF 0x7fffffff #define CENDL "\n" #define ll long long #define c_reverse(s) reverse(s.begin(), s.end()) #define c_sort(s) sort(s.begin(), s.end()) #define print_vector(v..
-
백준 2916번: 자와 각도기다이나믹프로그래밍(DP) 2018. 10. 21. 17:25
https://www.acmicpc.net/problem/2916 1. 문제 2. 알고리즘키워드 - DP - 접근법0 과 입력 받은, 각도도 만들수 있는 각으로 해야한다.만들어진 각도를 재활용 하여 다른 각도도 만들 수 있다. 3. 코드 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MAX..