啊啊啊啊啊
2024-08-30 14:34:04
发布于:上海
5阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
bool mark[101][101][101];
struct N {
int a, b, c;
int t;
};
queue<N> Q;
void AtoB(int &a ,int sa,int &b,int sb) {
if (sb - b >= a) {
b += a;
a = 0;
}
else {
a -= sb - b;
b = sb;
}
}
int BFS(int s, int m, int n) {
while (Q.empty() == false) {
N now = Q.front();
Q.pop();
int a, b, c;
a = now.a;
b = now.b;
c = now.c;
AtoB(a, s, b, n);
if (mark[a][b][c] == false) {
mark[a][b][c] = true;
N tmp;
tmp.a = a;
tmp.b = b;
tmp.c = c;
tmp.t = now.t + 1;
if (a == s / 2 && b == s / 2)
return tmp.t;
if (c == s / 2 && b == s / 2)
return tmp.t;
if (c == s / 2 && a == s / 2)
return tmp.t;
Q.push(tmp);
}
a = now.a;
b = now.b;
c = now.c;
AtoB(b, n, a, s);
if (mark[a][b][c] == false) {
mark[a][b][c] = true;
N tmp;
tmp.a = a;
tmp.b = b;
tmp.c = c;
tmp.t = now.t+1;
if (a == s / 2 && b == s / 2)
return tmp.t;
if (c == s / 2 && b == s / 2)
return tmp.t;
if (c == s / 2 && a == s / 2)
return tmp.t;
Q.push(tmp);
}
a = now.a;
b = now.b;
c = now.c;
AtoB(a, s, c, m);
if (mark[a][b][c] == false) {
mark[a][b][c] = true;
N tmp;
tmp.a = a;
tmp.b = b;
tmp.c = c;
tmp.t = now.t + 1;
if (a == s / 2 && b == s / 2)
return tmp.t;
if (c == s / 2 && b == s / 2)
return tmp.t;
if (c == s / 2 && a == s / 2)
return tmp.t;
Q.push(tmp);
}
a = now.a;
b = now.b;
c = now.c;
AtoB(c, m, a, s);
if (mark[a][b][c] == false) {
mark[a][b][c] = true;
N tmp;
tmp.a = a;
tmp.b = b;
tmp.c = c;
tmp.t = now.t + 1;
if (a == s / 2 && b == s / 2)
return tmp.t;
if (c == s / 2 && b == s / 2)
return tmp.t;
if (c == s / 2 && a == s / 2)
return tmp.t;
Q.push(tmp);
}
a = now.a;
b = now.b;
c = now.c;
AtoB(b, n, c, m);
if (mark[a][b][c] == false) {
mark[a][b][c] = true;
N tmp;
tmp.a = a;
tmp.b = b;
tmp.c = c;
tmp.t = now.t + 1;
if (a == s / 2 && b == s / 2)
return tmp.t;
if (c == s / 2 && b == s / 2)
return tmp.t;
if (c == s / 2 && a == s / 2)
return tmp.t;
Q.push(tmp);
}
a = now.a;
b = now.b;
c = now.c;
AtoB(c, m, b, n);
if (mark[a][b][c] == false) {
mark[a][b][c] = true;
N tmp;
tmp.a = a;
tmp.b = b;
tmp.c = c;
tmp.t = now.t + 1;
if (a == s / 2 && b == s / 2)
return tmp.t;
if (c == s / 2 && b == s / 2)
return tmp.t;
if (c == s / 2 && a == s / 2)
return tmp.t;
Q.push(tmp);
}
}
return -1;
}
int main() {
int s, n, m;
while (scanf("%d%d%d", &s,&n,&m) != EOF) {
if (s == 0)
break;
if (s % 2 == 1) {
puts("-1");
continue;
}
for (int i = 0; i <= s; i++) {
for (int j = 0; j <= n; j++) {
for (int k = 0; k <= m; k++) {
mark[i][j][k] = false;
}
}
}
N tmp;
tmp.a = s;
tmp.b = 0;
tmp.c = 0;
tmp.t = 0;
while (Q.empty() == false)
Q.pop();
Q.push(tmp);
mark[s][0][0] = true;
int rec = BFS(s, n, m);
if (rec == -1)
puts("-1");
else printf("%d\n", rec);
}
return 0;
}
全部评论 2
大佬你太厉害了,我好崇拜你哦
2024-08-31 来自 上海
0一己之力把正确率拉到50%以下...
2024-08-30 来自 上海
0
有帮助,赞一个