为啥答案小了?
查看原帖
为啥答案小了?
541522
_Fxlt_楼主2022/10/8 18:32
#include<iostream>
using namespace std;
int a1,b1,a2,b2;
bool goout[27][27];
pair<int,int> have[900];
int now = 0,all = 1;
int toa[13] = {0,-1,-2,-2,-2,-2,-1,1,2,2,2,2,1};
int tob[13] = {0,-2,-2,-1,1,2,2,2,2,1,-1,-2,-2};
int main()
{
	cin >> a1 >> b1 >> a2 >> b2;
	
	//马1
	goout[a1][b1] = true;
	have[0] = {a1,b2};
	int ans = 0;
	while(now < all)
	{
		ans++;
		int l = all - now;
		while(l--)
		{
			int x = 1;
			while(x <= 12)
			{
			    int a = have[now].first + toa[x];
			    int b = have[now].second + tob[x];
			    
			    if(a == 1 && b == 1)
			    {
			    	now = all;
			    	break;
				}
			    if(a > 0 && a <= a1 + 5 && b > 0 && b <= b1 + 5 && !goout[a][b] &&(a != a2 ||b != b2))
				{
					goout[a][b] = true;
					have[all] = {a,b};
					all++;
				}
				x++;
			}
			now++;
		}
	}
	cout << ans << "\n";
	cout << ans;
	return 0;
}

不知道为啥搜出来答案小了

2022/10/8 18:32
加载中...