[BOJ / C++] 2251 물통

Seulguo·2022년 7월 26일
0

Algorithm

목록 보기
134/185
post-thumbnail

🐣 문제

링크 : https://www.acmicpc.net/problem/2251


🐥 코드

#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

int A, B, C;
bool visited[201][201][201];
vector<int> v;

int main(){
    cin >> A >> B >> C;

    queue<pair<pair<int,int>, int>> q;
    q.push(make_pair(make_pair(0, 0), C));

    while(!q.empty()){
        int a = q.front().first.first;
        int b = q.front().first.second;
        int c = q.front().second;
        q.pop();

        if(visited[a][b][c] == true) continue;
        visited[a][b][c] = true;

        if(a == 0) v.push_back(c);

        if(a + b > B) q.push(make_pair(make_pair(a + b - B, B), c));
        else q.push(make_pair(make_pair(0, a + b), c));

        if(a + c > C) q.push(make_pair(make_pair(a + c - C, b), C));
        else q.push(make_pair(make_pair(0, b), a + c));

        if(b + a > A) q.push(make_pair(make_pair(A, b + a - A), c));
        else q.push(make_pair(make_pair(b + a, 0), c));

        if(b + c > C) q.push(make_pair(make_pair(a, b + c - C), c));
        else q.push(make_pair(make_pair(a, 0), b + c));

        if(c + a > A) q.push(make_pair(make_pair(A, b), c + a - A));
        else q.push(make_pair(make_pair(c + a, b), 0));

        if(c + b > B) q.push(make_pair(make_pair(a, B), c + b - B));
        else q.push(make_pair(make_pair(a, b + c), 0)); 
    }

    sort(v.begin(), v.end());
    for(int i = 0; i < v.size(); i++){
        cout << v[i] << " ";
    }
    cout << '\n';
    return 0;
}

0개의 댓글