#13230. 珅泽教育CSP-J第一轮模拟考第十七套 第 43 题

珅泽教育CSP-J第一轮模拟考第十七套 第 43 题

完善程序(2):三个杯子倒水

const int INF = 1000000000;
struct Node { int a, b; };
int dist[5001][5001];
int ans, cost;

void bfs(int cap[])
{
    queue<Node> q;
    q.push({0, 0});
    dist[0][0] = 0;
    while (!q.empty())
    {
        Node u = q.front(); q.pop();
        int a = u.a, b = u.b;
        int c = _____(1)_____;
        int cur = dist[a][b];
        for (int i = 0; i < 3; ++i)
        {
            for (int j = 0; j < 3; ++j)
            {
                int w[3] = {a, b, c};
                if (_____(2)_____) continue;
                int pour = _____(3)_____;
                w[i] -= pour;
                w[j] += pour;
                int na = w[0], nb = w[1];
                if (dist[na][nb] == -1)
                {
                    _____(4)_____;
                    q.push({na, nb});
                    int nc = cap[2] - na - nb;
                    if (_____(5)_____)
                    {
                        ans = na;
                        cost = cur + 1;
                    }
                    if (nb > 0 && (nb < ans || (nb == ans && cur + 1 < cost)))
                    {
                        ans = nb;
                        cost = cur + 1;
                    }
                    if (nc > 0 && (nc < ans || (nc == ans && cur + 1 < cost)))
                    {
                        ans = nc;
                        cost = cur + 1;
                    }
                }
            }
        }
    }
}

pair<int, int> solve(int cap[])
{
    ans = INF;
    cost = INF;
    for (int i = 0; i <= cap[0]; ++i)
        for (int j = 0; j <= cap[1]; ++j)
            dist[i][j] = -1;
    bfs(cap);
    return {ans, cost};
}

(3)处应填( )。

{{ select(1) }}

  • min(w[i], cap[j] - w[j])
  • min(w[i], cap[i] - w[j])
  • max(w[i], cap[j] - w[j])
  • min(w[j], cap[i] - w[i])