比赛 |
2025暑期集训第7场 |
评测结果 |
AAAAAAAAAA |
题目名称 |
倒水 |
最终得分 |
100 |
用户昵称 |
秋_Water |
运行时间 |
0.023 s |
代码语言 |
C++ |
内存使用 |
3.66 MiB |
提交时间 |
2025-08-11 17:06:45 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int A, B, C, X;
void bfs() {
set<tuple<int, int, int>> vis;
queue<tuple<int, int, int, int>> q;
q.push(make_tuple(A, 0, 0, 0));
vis.insert(make_tuple(A, 0, 0));
while (!q.empty()) {
auto now = q.front();
int nowa, nowb, nowc, bs;
tie(nowa, nowb, nowc, bs) = now;
q.pop();
if (nowa == X || nowb == X || nowc == X) {
cout << bs<<"\n";
return;
}
int tmp = min(nowa, B - nowb);
if (tmp > 0) {
int na = nowa - tmp;
int nb = nowb + tmp;
int nc = nowc;
auto newf = make_tuple(na, nb, nc);
if (!vis.count(newf)) {
vis.insert(newf);
q.push(make_tuple(na, nb, nc, bs + 1));
}
}
tmp = min(nowa, C - nowc);
if (tmp > 0) {
int na = nowa - tmp;
int nb = nowb;
int nc = nowc + tmp;
auto newf = make_tuple(na, nb, nc);
if (!vis.count(newf)) {
vis.insert(newf);
q.push(make_tuple(na, nb, nc, bs + 1));
}
}
tmp = min(nowb, A - nowa);
if (tmp > 0) {
int na = nowa + tmp;
int nb = nowb - tmp;
int nc = nowc;
auto newf = make_tuple(na, nb, nc);
if (!vis.count(newf)) {
vis.insert(newf);
q.push(make_tuple(na, nb, nc, bs + 1));
}
}
tmp = min(nowb, C - nowc);
if (tmp > 0) {
int na = nowa;
int nb = nowb - tmp;
int nc = nowc + tmp;
auto newf = make_tuple(na, nb, nc);
if (!vis.count(newf)) {
vis.insert(newf);
q.push(make_tuple(na, nb, nc, bs + 1));
}
}
tmp = min(nowc, A - nowa);
if (tmp > 0) {
int na = nowa + tmp;
int nb = nowb;
int nc = nowc - tmp;
auto newf = make_tuple(na, nb, nc);
if (!vis.count(newf)) {
vis.insert(newf);
q.push(make_tuple(na, nb, nc, bs + 1));
}
}
tmp = min(nowc, B - nowb);
if (tmp > 0) {
int na = nowa;
int nb = nowb + tmp;
int nc = nowc - tmp;
auto newf = make_tuple(na, nb, nc);
if (!vis.count(newf)) {
vis.insert(newf);
q.push(make_tuple(na, nb, nc, bs + 1));
}
}
}
cout <<"false\n";
}
int main() {
freopen("pourwater.in", "r", stdin);
freopen("pourwater.out", "w", stdout);
while(cin>>A){
cin>> B >> C >> X;
bfs();
}
return 0;
}