写的依托
2024-07-21 14:50:57
发布于:广东
1阅读
0回复
0点赞
蚌埠住了
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;
struct node{
vector <int> v;
int x = 0, y = 0, step = 0;
};
bool vis[1005][1005];
int n, m, k;
node bfs(){
node xxxxx;
queue <node> q;
q.push(xxxxx);
while(!q.empty()){
node head = q.front();
q.pop();
if(head.y == k) return head;
node tmp = head;
tmp.x = n;
if(!vis[tmp.x][tmp.y]){
vis[tmp.x][tmp.y] = 1;
tmp.step++, tmp.v.push_back(1);
q.push(tmp);
}
tmp = head;
tmp.y = m;
if(!vis[tmp.x][tmp.y]){
vis[tmp.x][tmp.y] = 1;
tmp.step++, tmp.v.push_back(2);
q.push(tmp);
}
tmp = head;
tmp.x = 0;
if(!vis[tmp.x][tmp.y]){
vis[tmp.x][tmp.y] = 1;
tmp.step++, tmp.v.push_back(3);
q.push(tmp);
}
tmp = head;
tmp.y = 0;
if(!vis[tmp.x][tmp.y]){
vis[tmp.x][tmp.y] = 1;
tmp.step++, tmp.v.push_back(4);
q.push(tmp);
}
tmp = head;
if(tmp.x + tmp.y <= n){
tmp.x += tmp.y, tmp.y = 0;
}else{
tmp.y -= (n - tmp.x), tmp.x = n;
}
if(!vis[tmp.x][tmp.y]){
vis[tmp.x][tmp.y] = 1;
tmp.step++, tmp.v.push_back(5);
q.push(tmp);
}
tmp = head;
if(tmp.x + tmp.y <= m){
tmp.y += tmp.x, tmp.x = 0;
}else{
tmp.x -= (m - tmp.y), tmp.y = m;
}
if(!vis[tmp.x][tmp.y]){
vis[tmp.x][tmp.y] = 1;
tmp.step++, tmp.v.push_back(6);
q.push(tmp);
}
}
return xxxxx;
}
int main(){
int t;
cin >> t;
while(t--){
memset(vis, 0, sizeof(vis));
cin >> n >> m >> k;
node ans = bfs();
cout << ans.step << ' ';
for(int i = 0; i < ans.v.size(); i++){
cout << ans.v[i] << ' ';
}cout << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个