比赛 |
2025暑期集训第7场 |
评测结果 |
WWAWWWWWWW |
题目名称 |
倒水 |
最终得分 |
10 |
用户昵称 |
Hollow07 |
运行时间 |
0.025 s |
代码语言 |
C++ |
内存使用 |
3.82 MiB |
提交时间 |
2025-08-11 15:50:24 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int A,B,C,x;
int dirs[6][2]={{0,1},{0,2},{1,0},{1,2},{2,0},{2,1}};
bool vis[100][100][100];
struct node {
int a,b,c;
int steps;
node(int aa,int bb,int cc,int ss):a(aa),b(bb),c(cc),steps(ss){}
};
int main(){
// freopen("in.in","r",stdin);
freopen("pourwater.in","r",stdin);
freopen("pourwater.out","w",stdout);
scanf("%lld %lld %lld %lld",&A,&B,&C,&x);
if (x==0||x==A){
printf("0");
return 0;
}else if (x<0||x>A){
printf("false");
return 0;
}else if (x>B&&x>C&&x!=A){
printf("false");
return 0;
}else if (A>B+C&&x<A-B-C){
printf("false");
return 0;
}
queue<node> q;
q.push(node(A,0,0,0));
vis[A][0][0]=1;
while (!q.empty()){
node u=q.front();
q.pop();
for (int d=0; d<6; ++d){
int from=dirs[d][0];
int to=dirs[d][1];
int a=u.a, b=u.b, c=u.c;
if (from==0 && to==1){// A→B
int amount=min(a,B-b);
a-=amount;
b+=amount;
} else if (from==0 && to==2){// A→C
int amount=min(a,C-c);
a-=amount;
c+=amount;
} else if (from==1 && to==0){// B→A
int amount=min(b,A-a);
b-=amount;
a+=amount;
} else if (from==1 && to==2){// B→C
int amount=min(b,C-c);
b-=amount;
c+=amount;
} else if (from==2 && to==0){// C→A
int amount=min(c,A-a);
c-= amount;
a+= amount;
} else if (from==2 && to==1){// C→B
int amount=min(c,B-b);
c-=amount;
b+=amount;
}
if (a<0||a>A||b<0||b>B||c<0||c>C)
continue;
if (vis[a][b][c])
continue;
if (a==x||b==x||c==x){
printf("%lld",u.steps+1);
return 0;
}
vis[a][b][c]=1;
q.push(node(a,b,c,u.steps+1));
}
}
printf("false");
return 0;
}