记录编号 |
605489 |
评测结果 |
AAAAAAAAAA |
题目名称 |
3659.[SYOI 2022]倒水 |
最终得分 |
100 |
用户昵称 |
汐汐很希希 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.028 s |
提交时间 |
2025-09-02 19:47:53 |
内存使用 |
3.71 MiB |
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int C=3;
const int N=110;
struct Node
{
int v[C],step;
};
int c[C],d;
bool vis[N][N];
int bfs()
{
queue<Node> q;q.push({{c[0],0,0},0});
vis[c[0]][c[1]]=true;
while(!q.empty())
{
Node x=q.front();q.pop();
if(x.v[0]==d||x.v[1]==d||x.v[2]==d) return x.step;
for(int i=0;i<C;i++)
for(int j=0;j<C;j++)
{
if(i==j) continue;
if(x.v[i]==0||x.v[j]==c[j]) continue;
Node y={{x.v[0],x.v[1],x.v[2]},x.step+1};
int t=min(x.v[i],c[j]-x.v[j]);
y.v[i]-=t,y.v[j]+=t;
if(vis[y.v[i]][y.v[j]]) continue;
q.push(y),vis[y.v[i]][y.v[j]]=1;
}
}
return -1;
}
int main()
{
freopen("pourwater.in","r",stdin);
freopen("pourwater.out","w",stdout);
for(int i=0;i<C;i++) cin>>c[i];
cin>>d;
int ans=bfs();
if(ans!=-1) cout<<ans<<endl;
else cout<<"false"<<endl;
return 0;
}