比赛 2025暑期集训第7场 评测结果 AAMAMWAMAA
题目名称 倒水 最终得分 60
用户昵称 zhyn 运行时间 1.603 s
代码语言 C++ 内存使用 74.29 MiB
提交时间 2025-08-11 16:35:33
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;

int n;
auto start=0; 
int v[4]; 
int x;


struct node{
	int a[4],d;
};
int ans=1;

queue<node>q; 

void bfs(){
	q.push({{0,v[1],0,0},0});
	while(!q.empty()){
		node f=q.front();
		node t=q.front();
		q.pop();
		ans++;
		if(ans>=15000000){
			cout<<"false";
			exit(0);
		} 
		for(int i=1;i<=3;i++){
			if(f.a[i]!=0){
				for(int j=1;j<=3;j++){
					if(f.a[j]!=v[j]&&i!=j){
						if(f.a[i]<=v[j]-f.a[j]){
							f.a[j]=f.a[j]+f.a[i];
							f.a[i]=0;
							
						}
						else{
							f.a[i]-=v[j]-f.a[j];
							f.a[j]=v[j];
						}
						if(f.a[i]==x||f.a[j]==x){
							cout<<f.d+1<<"\n";
							exit(0);
						}
						f.d++;
						q.push(f);
						f=t;
					}
				}
			}
		}
	}
	
}


int main(){
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	freopen("pourwater.in","r",stdin);
	freopen("pourwater.out","w",stdout); 
	
	for(int i=1;i<=3;i++){
		cin>>v[i];
	}
	
	cin>>x;
	if(v[1]<x){
		cout<<"false";
		return 0;
	}
	
	
	bfs();
	cout<<"false"; 
	
	
	
	return 0;
}