알고리즘/BOJ

백준 10162번 전자레인지

꾸준함. 2019. 1. 20. 22:27

문제 링크입니다: https://www.acmicpc.net/problem/10162


간단한 BFS(Breadth First Search) 알고리즘 문제였습니다.


#include <iostream>

#include <queue>

using namespace std;

 

const int MAX = 10000 + 1;

 

bool visited[MAX];

 

int main(void)

{

        ios_base::sync_with_stdio(0);

        cin.tie(0);

        int T;

        cin >> T;

 

        queue<pair<int, pair<int, pair<int, int>>>> q;

        q.push({ T, {0, {0, 0}} });

        visited[T] = true;

 

        while (!q.empty())

        {

                 int time = q.front().first;

                 int A = q.front().second.first;

                 int B = q.front().second.second.first;

                 int C = q.front().second.second.second;

                 q.pop();

 

                 if (time == 0)

                 {

                         cout << A << " " << B << " " << C << "\n";

                         return 0;

                 }

 

                 if (time - 300 >= 0 && !visited[time - 300])

                 {

                         visited[time - 300] = true;

                         q.push({ time - 300, {A + 1, {B, C}} });

                 }

                 if (time - 60 >= 0 && !visited[time - 60])

                 {

                         visited[time - 60] = true;

                         q.push({ time - 60, {A, {B + 1, C}} });

                 }

                 if (time - 10 >= 0 && !visited[time - 10])

                 {

                         visited[time - 10] = true;

                         q.push({ time - 10, {A, {B, C + 1}} });

                 }

        }

        cout << -1 << "\n";

        return 0;

}


개발환경:Visual Studio 2017


지적, 조언, 질문 환영입니다! 댓글 남겨주세요~

반응형

'알고리즘 > BOJ' 카테고리의 다른 글

백준 5988번 홀수일까 짝수일까  (0) 2019.01.22
백준 5904번 Moo 게임  (2) 2019.01.21
백준 14956번 Philosopher's Walk  (2) 2019.01.20
백준 16720번 BAZE RUNNER  (0) 2019.01.20
백준 1759번 암호 만들기  (0) 2019.01.20