社区讨论
样例都过了但是全是RE
P1432倒水问题参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @lo1itqug
- 此快照首次捕获于
- 2023/10/22 21:45 2 年前
- 此快照最后确认于
- 2023/11/02 22:39 2 年前
样例都过了但是全是RE,有没有大佬可以帮忙看一下ww,数组往大里开了就是MLE ;w;;;;;;;;;;;;;;;
CPP#include <bits/stdc++.h>
using namespace std;
struct Node
{
int x , y;
};
struct Node2
{
int x , y , z;
};
int n;
bool vis[1010][1010];
Node2 ans1[1010][1010];
int ansx , ansy;
void dfs(int x , int y)
{
// cout << x << " " << y << endl;
// cout << ans1[x][y].z << endl;
if (ans1[x][y].z == 0)
{
return ;
}
dfs(ans1[x][y].x, ans1[x][y].y);
if (ans1[x][y].z != -1)
{
cout << ans1[x][y].z << " ";
}
}
int bfs(int x , int y , int z)
{
queue <Node> q;
queue <int> s;
q.push({x , 0});
s.push(1);
q.push({0 , y});
s.push(1);
vis[x][0] = true;
vis[0][y] = true;
vis[0][0] = false;
while(!q.empty())
{
int a = q.front().x;
int b = q.front().y;
q.pop();
int step = s.front();
s.pop();
if (b == z)
{
// cout << step << endl;
ansx = a;
ansy = b;
return step;
}
for (int i = 1; i <= 6; i++)
{
if (a != x and i == 1)
{
if (vis[x][b] == false)
{
// cout << a << " " << b << " " << step << " " << i << endl ;
ans1[x][b].x = a;
ans1[x][b].y = b;
ans1[x][b].z = i;
q.push({x , b});
s.push(step + 1);
vis[x][b] = true;
}
}
else if (b != y and i == 2)
{
if (vis[a][y] == false)
{
ans1[a][y].x = a;
ans1[a][y].y = b;
ans1[a][y].z = i;
// cout << a << " " << b << " " << step << " " << i << endl ;
q.push({a , y});
s.push(step + 1);
vis[a][y] = true;
}
}
else if (i == 3 and a != 0)
{
if (vis[0][b] == false)
{
ans1[0][b].x = a;
ans1[0][b].y = b;
ans1[0][b].z = i;
// cout << a << " " << b << " " << step << " " << i << endl ;
q.push({0 , b});
s.push(step + 1);
vis[0][b] = true;
}
}
else if (i == 4 and b != 0)
{
if (vis[a][0] == false)
{
ans1[a][0].x = a;
ans1[a][0].y = b;
ans1[a][0].z = i;
// cout << a << " " << b << " " << step << " " << i << endl ;
q.push({a , 0});
s.push(step + 1);
vis[a][0] = true;
}
}
else if (i == 5)
{
if (x - a >= b)
{
if (vis[a + b][0] == false)
{
ans1[a + b][0].x = a;
ans1[a + b][0].y = b;
ans1[a + b][0].z = i;
// cout << a << " " << b << " " << step << " " << i << endl ;
q.push({a + b , 0});
s.push(step + 1);
vis[a + b][0] = true;
}
}
else
{
if (vis[x][b - (x - a)] == false)
{
ans1[x][b - (x - a)].x = a;
ans1[x][b - (x - a)].y = b;
ans1[x][b - (x - a)].z = i;
// cout << a << " " << b << " " << step << " " << i << endl ;
q.push({x , b - (x - a)});
s.push(step + 1);
vis[x][b - (x - a)] = true;
}
}
}
else if (i == 6)
{
if (y - b >= a)
{
if (vis[0][a + b] == false )
{
ans1[0][a + b].x = a;
ans1[0][a + b].y = b;
ans1[0][a + b].z = i;
// cout << a << " " << b << " " << step << " " << i << endl ;
q.push({0 , a + b});
s.push(step + 1);
vis[0][a + b] = true;
}
}
else
{
if (vis[a - (y - b)][y] == false )
{
ans1[a - (y - b)][y].x = a;
ans1[a - (y - b)][y].y = b;
ans1[a - (y - b)][y].z = i;
// cout << a << " " << b << " " << step << " " << i << endl ;
q.push({a - (y - b) , y});
s.push(step + 1);
vis[a - (y - b)][y] = true;
}
}
}
}
}
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
memset(vis , 0 , sizeof(vis));
memset(ans1 , -1 , sizeof(ans1));
int x , y , z;
cin >> x >> y >> z;
int ans = bfs(x , y, z);
ans1[x][0].z = 1;
ans1[0][y].z = 2;
cout << ans << " ";
dfs(ansx , ansy);
//cout << "----------------------" << endl;
cout << endl;
}
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...