比赛 2025暑期集训第7场 评测结果 AAWAAAAWAA
题目名称 倒水 最终得分 80
用户昵称 陆晨洗 运行时间 0.136 s
代码语言 C++ 内存使用 3.67 MiB
提交时间 2025-08-11 17:04:49
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x,ans;
int w[1000010][20]={0};int w1;

bool jc(int a1,int b1,int c1)
{
    int i,j;
    for(i=1;i<=w1;i++)
    {
        if(a1==w[i][1]&&b1==w[i][2]&&c1==w[i][3])
        {
            return false;
        }
    }
    w1++;
    w[w1][1]=a1;w[w1][2]=b1;w[w1][3]=c1;
    return true;
}
void ds(int a1,int b1,int c1,int out,int in,int step)
{
    //cout<<a1<<" "<<b1<<" "<<c1<<" "<<out<<" "<<in<<" "<<step<<" "<<w1<<endl;
    if(jc(a1,b1,c1)==false)
    {
        w1++;
        return;
    }
    if(a1==x||b1==x||c1==x)
    {
        ans=min(step,ans);
        return;
    }
    if(a1!=0)
    {
        if(b1!=b)
        {
            if(in!=1||out!=2)
            {
                if(a1-b+b1<0)
                {
                    ds(0,b1+a1,c1,1,2,step+1);
                }
                else
                {
                    ds(a1-b+b1,b,c1,1,2,step+1);
                }
                w1--;
            }
        }
        if(c1!=c)
        {
            if(in!=1||out!=3)
            {
                if(a1-c+c1<0)
                {
                    ds(0,b1,c1+a1,1,3,step+1);
                }
                else
                {
                    ds(a1-c+c1,b1,c,1,3,step+1);
                }
                w1--;
            }
        }
    }
    if(b1!=0)
    {
        if(a1!=a)
        {
            if(in!=2||out!=1)
            {
                if(b1-a+a1<0)
                {
                    ds(b1+a1,0,c1,2,1,step+1);
                }
                else
                {
                    ds(a,b1-a+a1,c1,2,1,step+1);
                }
                w1--;
            }
        }
        if(c1!=c)
        {
            if(in!=2||out!=3)
            {
                if(b1-c+c1<0)
                {
                    ds(a1,0,c1+b1,2,3,step+1);
                }
                else
                {
                    ds(a1,b1-c+c1,c,2,3,step+1);
                }
                w1--;
            }
        }
    }
    if(c1!=0)
    {
        if(b1!=b)
        {
            if(in!=3||out!=2)
            {
                if(c1-b+b1<0)
                {
                    ds(a1,b1+c1,0,3,2,step+1);
                }
                else
                {
                    ds(a1,b,c1-b+b1,3,2,step+1);
                }
                w1--;
            }
        }
        if(a1!=a)
        {
            if(in!=3||out!=1)
            {
                if(a1-b+b1<0)
                {
                    ds(c1+a1,b1,0,3,1,step+1);
                }
                else
                {
                    ds(a,b1,c1-a+a1,3,1,step+1);
                }
                w1--;
            }
        }
    }
    return;
}
int main()
{
    freopen("pourwater.in","r",stdin);
    freopen("pourwater.out","w",stdout);
    int i,j;
    cin>>a>>b>>c>>x;
    ans=1000000;w1=0;
    ds(a,0,0,0,0,0);
    cout<<ans;
    return 0;
}