0分求助!!!全WA
查看原帖
0分求助!!!全WA
748239
OIbishop楼主2022/11/26 12:36
#include <bits/stdc++.h>
using namespace std;

struct ff
{
	int x , y;
} a[1005] , b[1005];
int dp[1005][1005] , topa , topb , n , m;

int far (int aa , int bb)
{
	return (a[aa].x - b[bb].x) * (a[aa].x - b[bb].x) + (a[aa].y - b[bb].y) * (a[aa].y - b[bb].y); 
}

signed main ()
{
//	ios::sync_with_stdio (false);
	cin >> n >> m >> a[0].x >> a[0].y >> b[0].x >> b[0].y;
	for (register int i = 1; i <= n; i++)
	{
		char c; cin >> c;
		if (c == 'E') a[++topa].x = a[topa - 1].x + 1 , a[topa].y = a[topa - 1].y;
		if (c == 'S') a[++topa].y = a[topa - 1].y - 1 , a[topa].x = a[topa - 1].x;
		if (c == 'W') a[++topa].x = a[topa - 1].x - 1 , a[topa].y = a[topa - 1].y;
		if (c == 'N') a[++topa].y = a[topa - 1].y + 1 , a[topa].x = a[topa - 1].x;
	}
	for (register int i = 1; i <= m; i++)
	{
		char c; cin >> c;
		if (c == 'E') b[++topb].x = b[topb - 1].x + 1 , b[topb].y = b[topb - 1].y;
		if (c == 'S') b[++topb].y = b[topb - 1].y - 1 , b[topb].x = b[topb - 1].x;
		if (c == 'W') b[++topb].x = b[topb - 1].x - 1 , b[topb].y = b[topb - 1].y;
		if (c == 'N') b[++topb].y = b[topb - 1].y + 1 , b[topb].x = b[topb - 1].x;
	}
	for (int i = 1; i <= n; i++)
		dp[i][0] = far (i , 0) + dp[i - 1][0];
	for (int i = 1; i <= m; i++)
		dp[0][i] = far (0 , i) + dp[0][i - 1];
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			dp[i][j] = min (dp[i - 1][j] , min (dp[i][j - 1] , dp[i - 1][j - 1])) + far (i , j);
		}
	}
	cout << dp[n][m];
	return 0;
}
2022/11/26 12:36
加载中...