페이지

2251번: 물통

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


#include<stdio.h>
int max[3], h, t = 1, queue[3][802], check[201][201][201], tmp, ans[201], send[3];
int main()
{
    int i, j;
    scanf("%d%d%d", &max[0], &max[1], &max[2]);
    queue[0][1] = 0;
    queue[1][1] = 0;
    queue[2][1] = max[2];
    check[0][0][max[2]] = 1;
    ans[max[2]] = 1;
    while (h != t)
    {
        h++;
        for (i = 0; i<3; i++)
        {
            for (j = 0; j<3; j++)
            {
                if (i == j) continue;
                if ((i == 0 && j == 1) || (i == 1 && j == 0))
                {
                    tmp = 2;
                }
                else if ((i == 0 && j == 2) || (i == 2 && j == 0))
                {
                    tmp = 1;
                }
                else
                {
                    tmp = 0;
                }
                if (queue[i][h] <= max[j] - queue[j][h])
                {
                    send[i] = 0;
                    send[j] = queue[i][h] + queue[j][h];
                    send[tmp] = queue[tmp][h];
                }
                else
                {
                    send[i] = queue[i][h] + queue[j][h] - max[j];
                    send[j] = max[j];
                    send[tmp] = queue[tmp][h];
                }
                if (check[send[0]][send[1]][send[2]] == 0)
                {
                    queue[i][++t] = send[i];
                    queue[j][t] = send[j];
                    queue[tmp][t] = send[tmp];
                    if (send[0] == 0) ans[send[2]] = 1;
                    check[send[0]][send[1]][send[2]] = 1;
                }
            }
        }
    }
    for (i = 0; i <= 200; i++)
    {
        if (ans[i] == 1)
        {
            printf("%d ", i);
        }
    }
    return 0;
}

댓글 없음 :

댓글 쓰기