본문 바로가기

Algorithm

(203)
[BOJ] 23843번 콘센트 (C++) https://www.acmicpc.net/problem/23843 23843번: 콘센트 광재는 전자기기 대여사업을 시작했다. 퇴근하기 전에 다음날 손님들에게 빌려줄 N개의 전자기기를 충전하려 한다. 사용 가능한 콘센트는 M개가 있고, 성능은 모두 동일하다. 전자기기들은 한 www.acmicpc.net #include #include #include #include using namespace std; int main() { int n, m; cin >> n >> m; vector time(n); for(int i = 0; i > time[i]; } sort(time.begin(), time.end(), greater()); if(m > n){ // 예외처리 cout
[BOJ] 1700번 멀티탭 스케줄링 (C++) https://www.acmicpc.net/problem/1700 1700번: 멀티탭 스케줄링 기숙사에서 살고 있는 준규는 한 개의 멀티탭을 이용하고 있다. 준규는 키보드, 헤어드라이기, 핸드폰 충전기, 디지털 카메라 충전기 등 여러 개의 전기용품을 사용하면서 어쩔 수 없이 각종 전 www.acmicpc.net #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, k, answer = 0; cin >> n >> k; vector tap(n, -1); vector v(k); for(int i = 0; i > v[i]; } for(in..
[BOJ] 11123번 양 한마리... 양 두마리... (C++) https://www.acmicpc.net/problem/11123 11123번: 양 한마리... 양 두마리... 얼마전에 나는 불면증에 시달렸지... 천장이 뚫어져라 뜬 눈으로 밤을 지새우곤 했었지. 그러던 어느 날 내 친구 광민이에게 나의 불면증에 대해 말했더니 이렇게 말하더군. "양이라도 세봐!" www.acmicpc.net #include #include #include using namespace std; int t, h, w, cnt = 0; char arr[100][100]; bool visited[100][100]; int dx[4] = { -1, 0, 0, 1 }; int dy[4] = { 0, -1, 1, 0 }; void bfs(int a, int b){ queue q; q.push(..
[BOJ] 3184번 양 (C++) https://www.acmicpc.net/problem/3184 3184번: 양 첫 줄에는 두 정수 R과 C가 주어지며(3 ≤ R, C ≤ 250), 각 수는 마당의 행과 열의 수를 의미한다. 다음 R개의 줄은 C개의 글자를 가진다. 이들은 마당의 구조(울타리, 양, 늑대의 위치)를 의미한다. www.acmicpc.net #include #include using namespace std; int r, c; char arr[250][250]; bool visited[250][250]; int dx[4] = { -1, 0, 0, 1 }; int dy[4] = { 0, -1, 1, 0 }; int cs = 0, cw = 0; void bfs(int a, int b){ int ts = 0, tw = 0; q..
[BOJ] 2589번 보물섬 (C++) https://www.acmicpc.net/problem/2589 2589번: 보물섬 보물섬 지도를 발견한 후크 선장은 보물을 찾아나섰다. 보물섬 지도는 아래 그림과 같이 직사각형 모양이며 여러 칸으로 나뉘어져 있다. 각 칸은 육지(L)나 바다(W)로 표시되어 있다. 이 지도에서 www.acmicpc.net #include #include using namespace std; int n, m; char arr[50][50]; int path[50][50] = {-1, }; int dx[4] = {0, 0, -1, 1}; int dy[4] = {-1, 1, 0, 0}; int maxlen = 0; void bfs(int x, int y){ queue q; q.push({x, y}); path[x][y] =..
[BOJ] 2636번 치즈 (C++) https://www.acmicpc.net/problem/2636 2636번: 치즈 첫째 줄에는 사각형 모양 판의 세로와 가로의 길이가 양의 정수로 주어진다. 세로와 가로의 길이는 최대 100이다. 판의 각 가로줄의 모양이 윗 줄부터 차례로 둘째 줄부터 마지막 줄까지 주어진 www.acmicpc.net #include #include #include using namespace std; int arr[100][100]; bool visited[100][100]; int n, m; int dx[4] = { -1, 0, 0, 1 }; int dy[4] = { 0, -1, 1, 0 }; int time, result; bool bfs(){ int cnt = 0; queue q; q.push({0, 0}); v..
[Programmers] 거리두기 확인하기 (C++) https://programmers.co.kr/learn/courses/30/lessons/81302 코딩테스트 연습 - 거리두기 확인하기 [["POOOP", "OXXOX", "OPXPX", "OOXOX", "POXXP"], ["POOPX", "OXPXP", "PXXXO", "OXXXO", "OOOPP"], ["PXOPX", "OXOXP", "OXPOX", "OXXOP", "PXPOX"], ["OOOXX", "XOOOX", "OOOXX", "OXOOX", "OOOOO"], ["PXPXP", "XPXPX", "PXPXP", "XPXPX", "PXPXP"]] [1, 0, 1, 1, 1] programmers.co.kr #include #include #include #include using namespac..
[BOJ] 20300번 서강근육맨 (C++) https://www.acmicpc.net/problem/20300 20300번: 서강근육맨 PT 첫째 날에 $1$과 $4$를 선택하고, 둘째 날에 $2$와 $3$을 선택하고, 마지막 날에 $5$를 선택하면 $M$은 $5$가 되며, 이때가 $M$이 최소일 때이다. www.acmicpc.net #include #include #include using namespace std; int main() { int n; long long t; cin >> n; vector v; for(int i = 0; i > t; v.push_back(t); } sort(v.begin(), v.end()); long long max = 0; if(n % 2 == 0){ for(int i = 0; i..