1 条题解

  • -1
    @ 2023-8-19 20:57:17
    #include<bits/stdc++.h>
    using namespace std;
    map<vector<int>,int> mp;//定义这样一个映射用来反应当前情况的vector是否出现过
    vector<int> start(3);//每个桶的容量
    vector<int> a(3); //初始状态的桶的情况
    set<int> res;
    int main()
    {
        for(int i=0;i<3;i++)
        {
            cin>>start[i];
        }
        a[2]=start[2];
        queue<vector<int> > q;
        q.push(a);
        while(!q.empty())
        {
            vector<int> temp = q.front();
            q.pop();
            mp[temp]=1;
            if(temp[0]==0)
            {
                res.insert(temp[2]);
            }
            for(int i=0;i<3;i++)
            {
                if(temp[i]!=0)//某一个桶不为0,则可以向其他桶到
                {
                    for(int j=0;j<3;j++)
                    {
                        if(i==j) continue;//不能给自己倒
                        vector<int> new_arr=temp;
                        if(temp[j]<start[j]) //当前容量小于初始最大值
                        {
                            new_arr[j]=min(temp[i]+temp[j],start[j]);
                            new_arr[i]=max(0,temp[i]+temp[j]-start[j]);
                            if(mp[new_arr]!=1)
                            {
                                q.push(new_arr);
                            }
    
                        }
                    }
                }
            }
        }
        for(auto it=res.begin();it!=res.end();it++)
        {
            cout<<*it<<" ";
        }
        cout<<"\n";
        return 0;
    }
    
     
     
    
    
    • 1

    信息

    ID
    1601
    时间
    1000ms
    内存
    256MiB
    难度
    6
    标签
    递交数
    27
    已通过
    10
    上传者