본문 바로가기

Algorithm32

(BOJ) 5427 풀이 5427 #include #define X first #define Y second using namespace std; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int fire[1002][1002], ar[1002][1002], visited[1002][1002]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int T, w, h, flag = 0; cin >> T; while (T--) { flag = 0; cin >> w >> h; for (int i = 0; i < h; i++) { fill(fire[i], fire[i] + w, -1); fill(visited[i], visited[i] + w.. 2022. 2. 8.
(BOJ) 1697 풀이 1697 #include using namespace std; int visited[100002]; int main(void){ ios::sync_with_stdio(0);cin.tie(0); queue Q; fill(visited,visited+100002,-1); int N,K; cin >> N >> K; Q.push(N); visited[N]=0; while(visited[K]==-1){ int cur=Q.front(); Q.pop(); for(int nxt:{cur-1,cur+1, cur*2}){ if(nxt100000 || visited[nxt]!=-1)continue; Q.push(nxt); visited[nxt]=visited[cur]+1; } } cout 2022. 2. 7.
(BOJ) 1926 풀이 #include #define X first #define Y second using namespace std; int BFS(int x, int y); int ar[502][502], visited[502][502]; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; queue Q; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int N, M, count = 0, max = 0; cin >> N >> M; for (int i = 1; i ar[i][j]; } for (int i = 1; i 2022. 2. 4.
(BOJ) 2504 풀이 #include using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); string input; cin >> input; stack S; int flag = 0, ans = 0, tmp = 1; for (int i = 0; i < input.size(); i++) { if (input[i] == &#39;(&#39;) { tmp *= 2; S.push(input[i]); } if (input[i] == &#39;[&#39;) { tmp *= 3; S.push(input[i]); } if (input[i] == &#39;)&#39;) { if (input[i - 1] == &#39;(&#39;) // 2 { S.pop(); an.. 2022. 2. 3.