比赛 |
2025暑期集训第7场 |
评测结果 |
AAAAAAAAAA |
题目名称 |
倒水 |
最终得分 |
100 |
用户昵称 |
LikableP |
运行时间 |
0.030 s |
代码语言 |
C++ |
内存使用 |
3.86 MiB |
提交时间 |
2025-08-11 15:16:02 |
显示代码纯文本
#include <cstdio>
#include <map>
#include <queue>
using namespace std;
struct ITEM {
int a, b, c;
bool operator<(const ITEM &src) const {
if (a != src.a) return a < src.a;
if (b != src.b) return b < src.b;
return c < src.c;
}
};
struct NODE {
ITEM water;
int step;
};
int A, B, C, x;
queue<NODE> q;
map<ITEM, bool> vis;
int main() {
freopen("pourwater.in", "r", stdin);
freopen("pourwater.out", "w", stdout);
scanf("%d %d %d %d", &A, &B, &C, &x);
q.push({A, 0, 0, 0});
while (!q.empty()) {
NODE now = q.front();
q.pop();
if (now.water.a == x || now.water.b == x || now.water.c == x) {
printf("%d\n", now.step);
return 0;
}
if (vis[now.water]) continue;
vis[now.water] = 1;
int a = now.water.a, b = now.water.b, c = now.water.c;
// printf("[%d %d %d %d]\n", a, b, c, now.step);
// a -> b
int pour = min(B - b, a);
q.push({a - pour, b + pour, c, now.step + 1});
// a -> c
pour = min(C - c, a);
q.push({a - pour, b, c + pour, now.step + 1});
// b -> a
pour = min(A - a, b);
q.push({a + pour, b - pour, c, now.step + 1});
// b -> c
pour = min(C - c, b);
q.push({a, b - pour, c + pour, now.step + 1});
// c -> a
pour = min(A - a, c);
q.push({a + pour, b, c - pour, now.step + 1});
// c -> b
pour = min(B - b, c);
q.push({a, b + pour, c - pour, now.step + 1});
}
printf("false\n");
return 0;
}