Algorithm(218)
-
[BOJ] 1697번 : 숨바꼭질
1. problem : https://www.acmicpc.net/problem/1697 2. solution 1 :#include using namespace std; int board[200005]; int pos1, pos2; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> pos1 >> pos2; fill(board, board + 200005, -1); queue Q; if (pos1 == pos2) { cout = 0 && board[dx1] == -1) { board[dx1] = board[current] + 1; Q.push(dx1); if (dx1 == pos2) { cout = 0 && board[..
2024.08.13 -
[BOJ] 4179번 : 불!
1. problem : https://www.acmicpc.net/problem/4179 2. solution 1 :#include using namespace std; #define X first #define Y second int rows, cols; string board[1005];int minutes_f[1005][1005];int minutes_j[1005][1005];int dx[4] = { 1,0,-1,0 };int dy[4] = { 0,1,0,-1 };int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> rows >> cols; // board 값 채우기 for (int i = 0; i > board[i]; } // minut..
2024.08.13 -
[BOJ] 7576번 : 토마토
1. problem : https://www.acmicpc.net/problem/7576 2. solution 1 :#include using namespace std;#define X first #define Y second int dx[4] = { 0,1,0,-1 };int dy[4] = { 1,0,-1,0 };int days[1005][1005]; int board[1005][1005]; int rows, cols; int main(void) { ios::sync_with_stdio(0); cin.tie(0); queue> Q; cin >> cols >> rows; // board에 값 입력받기 for (int i = 0; i > board[i][j]; if (board[i][j] == 1..
2024.08.13 -
[BOJ] 10804번 : 카드 역배치
1. problem :https://www.acmicpc.net/problem/10804 2. solution 1 :nums = [i+1 for i in range(20)] n = 1 while (n > 0): n -= 1 start_idx,end_idx = map(int,input().split()) nums = nums[:start_idx-1] + list(reversed(nums[start_idx-1:end_idx])) + nums[end_idx:] print(' '.join(map(str,nums)))stl reverse를 이용한 풀이다. 3. solution 2 :#include using namespace std;int num[21];// 카드를 역순으로 놓는 함수void..
2024.08.12 -
[BOJ] 1267번 : 핸드폰 요금
1. problem :https://www.acmicpc.net/problem/1267 2. solution 1 :#include using namespace std;int main(void) { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; int young = 0; int minS = 0; while (N--) { int x; cin >> x; int young_r = x / 30; int min_r = x / 60; young += (young_r + 1)* 10; minS += (min_r + 1) * 15; } if (young 29와 59로 나누었을 때 error가 났다. 이때, 30과 60으로 나누는 대신, 기존값에 무조건 ..
2024.08.12 -
[BOJ] 4949번 : 균형잡힌 세상
1. problem : https://www.acmicpc.net/problem/4949 2. solution 1 :#include using namespace std;int main(void) { ios::sync_with_stdio(0); cin.tie(0); while (true) { string words; stack s; getline(cin, words); bool isBalanced = true; if (words == ".") break; for (auto c : words) { if (c == '[' || c == '(') s.push(c); else if (c == ']' || c == ')') { if (s.empty()) { // 예외처리 : stack이 비..
2024.08.08