比赛 2025暑期集训第7场 评测结果 AAAAAAAAAA
题目名称 倒水 最终得分 100
用户昵称 Ruyi 运行时间 0.028 s
代码语言 C++ 内存使用 3.67 MiB
提交时间 2025-08-11 16:49:58
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int A,B,C,x,ans;
struct node{
    int a,b,c,t;
    bool operator<(node y)const{return a^y.a?a>y.a:(b^y.b?b>y.b:(c^y.c?c>y.c:t>y.t));}
};
queue<node> q;
map<node,int> m;
int main(){
    freopen("pourwater.in","r",stdin);
    freopen("pourwater.out","w",stdout);
    cin>>A>>B>>C>>x;
    q.push({A,0,0,0});
    while(!q.empty()){
        int a=q.front().a,b=q.front().b,c=q.front().c,t=q.front().t;
        q.pop();
        m[{a,b,c,0}]=1;
        if(a==x||b==x||c==x){
            cout<<t<<endl;
            return 0;
        }
        if(a-B+b>=0&&m[{a-B+b,B,c,0}]==0) q.push({a-B+b,B,c,t+1});
        else if(a-B+b<0&&m[{0,b+a,c,0}]==0) q.push({0,b+a,c,t+1});
        if(c-B+b>=0&&m[{a,B,c-B+b,0}]==0) q.push({a,B,c-B+b,t+1});
        else if(c-B+b<0&&m[{a,b+c,0,0}]==0) q.push({a,b+c,0,t+1});
        if(a-C+c>=0&&m[{a-C+c,b,C,0}]==0) q.push({a-C+c,b,C,t+1});
        else if(a-C+c<0&&m[{0,b,c+a,0}]==0) q.push({0,b,c+a,t+1});
        if(b-C+c>=0&&m[{a,b-C+c,C,0}]==0) q.push({a,b-C+c,C,t+1});
        else if(b-C+c<0&&m[{a,0,c+b,0}]==0) q.push({a,0,c+b,t+1});
        if(b-A+a>=0&&m[{A,b-A+a,c,0}]==0) q.push({A,b-A+a,c,t+1});
        else if(b-A+a<0&&m[{a+b,0,c,0}]==0) q.push({a+b,0,c,t+1});
        if(c-A+a>=0&&m[{A,b,c-A+a,0}]==0) q.push({A,b,c-A+a,t+1});
        else if(c-A+a<0&&m[{a+c,b,0,0}]==0) q.push({a+c,b,0,t+1});
    }
    cout<<"false"<<endl;
    return 0;
}