본문 바로가기
Algorithm 💫/Problem Solving

[백준] 14226번: 이모티콘 / C++

by 돼지고기맛있다 2021. 9. 17.
반응형

✏️ 문제 링크

https://www.acmicpc.net/problem/14226

 

14226번: 이모티콘

영선이는 매우 기쁘기 때문에, 효빈이에게 스마일 이모티콘을 S개 보내려고 한다. 영선이는 이미 화면에 이모티콘 1개를 입력했다. 이제, 다음과 같은 3가지 연산만 사용해서 이모티콘을 S개 만

www.acmicpc.net

 

✏️ 문제 설명 (더보기 클릭 👆🏻)

 

✏️ 문제 코드

#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⭐  

 

 

반응형

댓글