比赛 2025暑期集训第7场 评测结果 AAAAAAAAAA
题目名称 倒水 最终得分 100
用户昵称 ChenBp 运行时间 0.028 s
代码语言 C++ 内存使用 3.75 MiB
提交时间 2025-08-11 16:58:05
显示代码纯文本
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
struct node {
    int s[3], t;
};
queue<node> q;
bool visited[105][105][105];
int main() {
    freopen("pourwater.in", "r", stdin);
    freopen("pourwater.out", "w", stdout);
    int s[3], x;
    cin >> s[0] >> s[1] >> s[2] >> x;
    node now;
    now.s[0] = s[0];
    now.s[1] = 0;
    now.s[2] = 0;
    now.t = 0;
    visited[s[0]][0][0] = true;
    q.push(now);
    while (!q.empty()) {
        now = q.front();
        q.pop();
        // cout << now.s[0] << " " << now.s[1] << " " << now.s[2] << " " << now.t << endl;
        if (now.s[0] == x || now.s[1] == x || now.s[2] == x) {
            cout << now.t;
            return 0;
        }
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (i == j)
                    continue;
                node tmp;
                tmp.s[0] = now.s[0];
                tmp.s[1] = now.s[1];
                tmp.s[2] = now.s[2];
                tmp.s[i] -= min(now.s[i], s[j] - now.s[j]);
                tmp.s[j] += min(now.s[i], s[j] - now.s[j]);
                tmp.t = now.t + 1;
                if (!visited[tmp.s[0]][tmp.s[1]][tmp.s[2]]) {
                    visited[tmp.s[0]][tmp.s[1]][tmp.s[2]] = true;
                    q.push(tmp);
                }
            }
        }
    }
    cout << "false";
    return 0;
}