본문 바로가기

BOJ

(179)
[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] 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..
[BOJ] 12813번 이진수 연산 (C++) https://www.acmicpc.net/problem/12813 12813번: 이진수 연산 총 100,000 비트로 이루어진 이진수 A와 B가 주어진다. 이때, A & B, A | B, A ^ B, ~A, ~B를 한 값을 출력하는 프로그램을 작성하시오. www.acmicpc.net #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); char a[100001]; char b[100001]; cin >> a >> b; // A & B for(int i = 0; i < strlen(a); i++){ if(a[i] == '1' && b[i] == '1') cout
[BOJ] 10974번 모든 순열 (C++) https://www.acmicpc.net/problem/10974 10974번: 모든 순열 N이 주어졌을 때, 1부터 N까지의 수로 이루어진 순열을 사전순으로 출력하는 프로그램을 작성하시오. www.acmicpc.net sol 1) next_permutation을 이용 #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector v; for(int i = 0; i < n; i++){ v.push_back(i + 1); } do{ for(int i = 0; i < n; i++){ cout
[BOJ] 11659번 구간 합 구하기 4 (C++) https://www.acmicpc.net/problem/11659 11659번: 구간 합 구하기 4 첫째 줄에 수의 개수 N과 합을 구해야 하는 횟수 M이 주어진다. 둘째 줄에는 N개의 수가 주어진다. 수는 1,000보다 작거나 같은 자연수이다. 셋째 줄부터 M개의 줄에는 합을 구해야 하는 구간 i와 j www.acmicpc.net #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, num, x, y; cin >> n >> m; vector v(n + 1); for(int i = 1; i > num; v[i] = v[i - 1] + num..
[BOJ] 17298번 오큰수 (C++) https://www.acmicpc.net/problem/17298 17298번: 오큰수 첫째 줄에 수열 A의 크기 N (1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에 수열 A의 원소 A1, A2, ..., AN (1 ≤ Ai ≤ 1,000,000)이 주어진다. www.acmicpc.net #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, num; cin >> n; vector v; stack s; vector res; for(int i = 0; i > num; v.push_back(num..