Hard deck/리포트

049 : 물의 양 구하기

서버관리자 페페 2022. 8. 8. 20:19
(Briefing)
(문제) (단 하나의 맥락) (입출력과 되어야 하는 그림)
     

 

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    // Argument supply
    static int[] Sender = {0, 0, 1, 1, 2, 2};
    static int[] Receiver = {1, 2, 0, 2, 0, 1};
    static boolean visited[][];
    static boolean answer[];
    static int now[];

    public static void main(String[] args) {

        // Input Supply Cable
        Scanner sc = new Scanner(System.in);
        now = new int[3];
        now[0] = sc.nextInt();
        now[1] = sc.nextInt();
        now[2] = sc.nextInt();

        
        // Preprocessing
        visited = new boolean[201][201];
        answer = new boolean[201];

        
        // Operating BFS
        BFS();

        
        // Output Extracting Cable
        for (int i = 0; i < answer.length; i++) {
            if (answer[i]) System.out.print(i + " ");
        }
    }

    
    // External Module BFS
    public static void BFS() {
        Queue<AB> queue = new LinkedList<>();
        queue.add(new AB(0, 0));
        visited[0][0] = true;
        answer[now[2]] = true;
        while (!queue.isEmpty()) {
            AB p = queue.poll();
            int A = p.A;
            int B = p.B;
            int C = now[2] - A - B;

            for (int k = 0; k < 6; k++) {
                int[] next = {A, B, C};
                next[Receiver[k]] += next[Sender[k]];
                next[Sender[k]] = 0;

                if (next[Receiver[k]] > now[Receiver[k]]) {
                    next[Sender[k]] = next[Receiver[k]] - now[Receiver[k]];
                    next[Receiver[k]] = now[Receiver[k]];
                }

                if (!visited[next[0]][next[1]]) {
                    visited[next[0]][next[1]] = true;
                    queue.add(new AB(next[0], next[1]));
                    if (next[0] == 0) {
                        answer[next[2]] = true;
                    }
                }
            }
        }
    }
}


// External Class AB
class AB {
    int A;
    int B;
    public AB(int A, int B) {
        this.A = A;
        this.B = B;
    }
}

'Hard deck > 리포트' 카테고리의 다른 글

060 : 세일즈맨의 고민  (0) 2022.08.08
057 : 최소 비용 구하기  (0) 2022.08.08
048 : Bipartite graph 판별하기  (0) 2022.08.08
047 : 효율적으로 해킹하기  (2) 2022.08.08
046 : 특정 거리의 도시 찾기  (0) 2022.08.08