Study/Coding Test
-
[Time Complexity] PermMissingElemStudy/Coding Test 2022. 7. 30. 14:31
문제 An array A consisting of N different integers is given. The array contains integers in the range [1..(N + 1)], which means that exactly one element is missing. Your goal is to find that missing element. Write a function: int solution(vector &A); that, given an array A, returns the value of the missing element. For example, given array A such that: A[0] = 2 A[1] = 3 A[2] = 1 A[3] = 5 the funct..
-
[백준] 빗물Study/Coding Test 2021. 10. 23. 00:11
https://www.acmicpc.net/problem/1662 1662번: 압축 압축되지 않은 문자열 S가 주어졌을 때, 이 문자열중 어떤 부분 문자열은 K(Q)와 같이 압축 할 수 있다. K는 한자리 정수이고, Q는 0자리 이상의 문자열이다. 이 Q라는 문자열이 K번 반복된다는 뜻이 www.acmicpc.net 아직 부족하다고 많이 느끼게 해준 문제... 간단해보이지만 바로 로직이 생각나지 않았다. #define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include using namespace std; int H, W; int answer; vector v; void input() { cin >> H >> W; for (int ..
-
[백준] 경사로Study/Coding Test 2021. 10. 22. 15:46
https://www.acmicpc.net/problem/14890 14890번: 경사로 첫째 줄에 N (2 ≤ N ≤ 100)과 L (1 ≤ L ≤ N)이 주어진다. 둘째 줄부터 N개의 줄에 지도가 주어진다. 각 칸의 높이는 10보다 작거나 같은 자연수이다. www.acmicpc.net 인덱싱에 주의해야 함. #define_CRT_SECURE_NO_DEPRECATE #include #include #include #include #include using namespace std; int N, L; int answer; int board[100][100]; void init() { memset(board, 0, sizeof(board)); } void input() { cin >> N >> L; for..
-
[백준] 스타트 택시Study/Coding Test 2021. 10. 22. 14:37
https://www.acmicpc.net/problem/19238 19238번: 스타트 택시 첫 줄에 N, M, 그리고 초기 연료의 양이 주어진다. (2 ≤ N ≤ 20, 1 ≤ M ≤ N2, 1 ≤ 초기 연료 ≤ 500,000) 연료는 무한히 많이 담을 수 있기 때문에, 초기 연료의 양을 넘어서 충전될 수도 있다. 다 www.acmicpc.net 시간초과 되었던 문제. 최소거리를 구하기 위해 BFS 사용하였더니 해결. #define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include #include using namespace std; struct Customer { int depart_r; //출발지 int depart_c; ..
-
[백준] 로봇 청소기Study/Coding Test 2021. 10. 21. 21:28
https://www.acmicpc.net/problem/14503 14503번: 로봇 청소기 로봇 청소기가 주어졌을 때, 청소하는 영역의 개수를 구하는 프로그램을 작성하시오. 로봇 청소기가 있는 장소는 N×M 크기의 직사각형으로 나타낼 수 있으며, 1×1크기의 정사각형 칸으로 나누어 www.acmicpc.net #define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include using namespace std; int N, M; //세로 가로 int robot_r, robot_c, robot_d; int answer; int board[50][50]; int dr[4] = { -1,0,1,0 }; int dc[4] = { 0,1..
-
[백준] 사다리 조작Study/Coding Test 2021. 10. 21. 21:26
https://www.acmicpc.net/problem/15684 15684번: 사다리 조작 사다리 게임은 N개의 세로선과 M개의 가로선으로 이루어져 있다. 인접한 세로선 사이에는 가로선을 놓을 수 있는데, 각각의 세로선마다 가로선을 놓을 수 있는 위치의 개수는 H이고, 모든 세로선 www.acmicpc.net 시간 초과 발생. dfs를 돌 때마다 r이 1부터 돌아서 문제였다. idx를 저장해두고, 그 idx부터 for문 돌리니까 통과. bool findPos(int idx, int cnt, int curr) { if (cnt == curr) { if (check()) { //print(); return true; } return false; } for (int r = idx; r lines; // {..
-
[백준] 모노미노도미노2Study/Coding Test 2021. 10. 19. 21:02
https://www.acmicpc.net/problem/20061 20061번: 모노미노도미노 2 모노미노도미노는 아래와 같이 생긴 보드에서 진행되는 게임이다. 보드는 빨간색 보드, 파란색 보드, 초록색 보드가 그림과 같이 붙어있는 형태이다. 게임에서 사용하는 좌표 (x, y)에서 x는 행, www.acmicpc.net 지우고 위에있던 타일을 밑으로 내려야한다는걸 까먹음. #define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include #include using namespace std; int N; int point, answer; vector blocks; //{t,x,y} int board[10][10]; void init..
-
[백준] 어른상어Study/Coding Test 2021. 10. 17. 23:11
https://www.acmicpc.net/problem/19237 19237번: 어른 상어 첫 줄에는 N, M, k가 주어진다. (2 ≤ N ≤ 20, 2 ≤ M ≤ N2, 1 ≤ k ≤ 1,000) 그 다음 줄부터 N개의 줄에 걸쳐 격자의 모습이 주어진다. 0은 빈칸이고, 0이 아닌 수 x는 x번 상어가 들어있는 칸을 의미 www.acmicpc.net 마지막에 answer >= 1000 조건에서 = 조건 안넣어서 틀림.... #define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include using namespace std; int answer; int N, M, k; struct Shark { int row; int col;..