求条
查看原帖
求条
734379
Shadow_T楼主2024/4/15 22:07
#include <bits/stdc++.h>
using namespace std;
int n,ca,cb;
bool vis[1001][1001];
struct point
{
	int a,b;
	string bz;
};
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		cin>>ca>>cb>>n;
		for(int i=0;i<=ca;i++)
		for(int j=0;j<=cb;j++)
		vis[i][j]=false;
		queue<point> q;
		q.push({0,0,""});
		vis[0][0]=true;
		while(!q.empty())
		{
			point t=q.front();
			if(t.b==n)
			{
				cout<<t.bz.size()<<" ";
				for(int i=0;i<t.bz[i];i++)
				cout<<t.bz[i]<<" ";
				cout<<"\n";
				break;
			}
			q.pop();
			if(!vis[ca][t.b])
			{
				vis[ca][t.b]=true;
				q.push({ca,t.b,t.bz+'1'});
			}
			if(!vis[t.a][cb])
			{
				vis[t.a][cb]=true;
				q.push({t.a,cb,t.bz+'2'});
			}
			if(!vis[0][t.b])
			{
				vis[0][t.b]=true;
				q.push({0,t.b,t.bz+'3'});
			}
			if(!vis[t.a][0])
			{
				vis[t.a][0]=true;
				q.push({t.a,0,t.bz+'4'});
			}
			int a=t.a,b=t.b;
			int d=min(b,ca-a);
			a+=d,b-=d;
			if(!vis[a][b])
			{
				vis[a][b]=true;
				q.push({a,b,t.bz+'5'});
			}
			a=t.a,b=t.b;
			d=min(a,cb-b);
			a-=d,b+=d;
			if(!vis[a][b])
			{
				vis[a][b]=true;
				q.push({a,b,t.bz+'6'});
			}
		}
	}
}
2024/4/15 22:07
加载中...