记录编号 604819 评测结果 AAAAAAAAAA
题目名称 3659.[SYOI 2022]倒水 最终得分 100
用户昵称 Gravatar秋_Water 是否通过 通过
代码语言 C++ 运行时间 0.028 s
提交时间 2025-08-12 08:03:26 内存使用 3.68 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int A, B, C, X;
void bfs() {
    set<tuple<int, int, int>> vis;
    queue<tuple<int, int, int, int>> q;
    q.push(make_tuple(A, 0, 0, 0));
    vis.insert(make_tuple(A, 0, 0));
    while (!q.empty()) {
        auto now = q.front();
        int nowa, nowb, nowc, bs;
        tie(nowa, nowb, nowc, bs) = now;
        q.pop();
        if (nowa == X || nowb == X || nowc == X) {
            cout << bs<<"\n";
            return;
        }
        int tmp = min(nowa, B - nowb);
        if (tmp > 0) {
            int na = nowa - tmp;
            int nb = nowb + tmp;
            int nc = nowc;
            auto newf = make_tuple(na, nb, nc);
            if (!vis.count(newf)) {
                vis.insert(newf);
                q.push(make_tuple(na, nb, nc, bs + 1));
            }
        }
        tmp = min(nowa, C - nowc);
        if (tmp > 0) {
            int na = nowa - tmp;
            int nb = nowb;
            int nc = nowc + tmp;
            auto newf = make_tuple(na, nb, nc);
            if (!vis.count(newf)) {
                vis.insert(newf);
                q.push(make_tuple(na, nb, nc, bs + 1));
            }
        }
        tmp = min(nowb, A - nowa);
        if (tmp > 0) {
            int na = nowa + tmp;
            int nb = nowb - tmp;
            int nc = nowc;
            auto newf = make_tuple(na, nb, nc);
            if (!vis.count(newf)) {
                vis.insert(newf);
                q.push(make_tuple(na, nb, nc, bs + 1));
            }
        }
        tmp = min(nowb, C - nowc);
        if (tmp > 0) {
            int na = nowa;
            int nb = nowb - tmp;
            int nc = nowc + tmp;
            auto newf = make_tuple(na, nb, nc);
            if (!vis.count(newf)) {
                vis.insert(newf);
                q.push(make_tuple(na, nb, nc, bs + 1));
            }
        }
        tmp = min(nowc, A - nowa);
        if (tmp > 0) {
            int na = nowa + tmp;
            int nb = nowb;
            int nc = nowc - tmp;
            auto newf = make_tuple(na, nb, nc);
            if (!vis.count(newf)) {
                vis.insert(newf);
                q.push(make_tuple(na, nb, nc, bs + 1));
            }
        }
        tmp = min(nowc, B - nowb);
        if (tmp > 0) {
            int na = nowa;
            int nb = nowb + tmp;
            int nc = nowc - tmp;
            auto newf = make_tuple(na, nb, nc);
            if (!vis.count(newf)) {
                vis.insert(newf);
                q.push(make_tuple(na, nb, nc, bs + 1));
            }
        }
    }
    cout <<"false\n";
}

int main() {
    freopen("pourwater.in", "r", stdin);
    freopen("pourwater.out", "w", stdout);	
    while(cin>>A){
    	cin>> B >> C >> X;
    	bfs();
	}
    
    return 0;
}