반응형
✏️ 문제 링크
https://www.acmicpc.net/problem/14226
✏️ 문제 설명 (더보기 클릭 👆🏻)
✏️ 문제 코드
#include <bits/stdc++.h>
using namespace std;
typedef struct Node{
int c; int s; int t;
}Node;
bool vis[1001][1001];
int main(){
int S; cin>>S;
queue<Node> q; q.push({0,1,0});
for(int i=0; i<1001; i++)
for(int j=0; j<1001; j++)
vis[i][j]=false;
while(!q.empty()){
Node t=q.front(); q.pop();
int clip=t.c; int screen=t.s; int seconds=t.t;
vis[clip][screen]=true;
if(screen==S){
cout<<seconds<<"\n";
return 0;
}
if(screen>0 and screen<1001 and !vis[screen][screen]) q.push({screen, screen, seconds+1});
if(screen+clip<1001 and !vis[clip][screen+clip] and clip>0) q.push({clip, screen+clip, seconds+1});
if(screen-1>=0 and !vis[clip][screen-1]) q.push({clip, screen-1, seconds+1});
}
return 0;
}
⭐ if feedback and question : comment please⭐
반응형
'Algorithm 💫 > Problem Solving' 카테고리의 다른 글
[백준] 1753번: 최단 경로 / C++ (0) | 2021.09.24 |
---|---|
[백준] 12851번: 숨바꼭질2 / C++ (0) | 2021.09.17 |
[백준] 13549번: 숨바꼭질3 / C++ (0) | 2021.09.17 |
[백준] 17086번: 아기상어 2 / C++ (0) | 2021.09.17 |
[백준] 16953번: A -> B / C++ (0) | 2021.09.16 |
댓글