想知道3、4两个数据是啥,只开一个数组怎么WA呢?标答一个是5一个是2
查看原帖
想知道3、4两个数据是啥,只开一个数组怎么WA呢?标答一个是5一个是2
257317
Lemon_Meow楼主2022/3/31 13:38

#include<iostream>
using namespace std;

int P1002() {
	int tx, ty, hx, hy;
	cin >> tx >> ty >> hx >> hy;

	int map[23][23] = {0}; //初始化

	if (hx>0    && hy>1   )   map[hx - 1][hy - 2] = -1; //8个点
	if (hx>1    && hy>0   )   map[hx - 2][hy - 1] = -1;
	if (hx>0    && hy<ty-1)   map[hx - 1][hy + 2] = -1;
	if (hx>1    && hy<ty  )   map[hx - 2][hy + 1] = -1;
	if (hx<tx   && hy>1   )   map[hx + 1][hy - 2] = -1;
	if (hx<tx-1 && hy>0   )   map[hx + 2][hy - 1] = -1;
	if (hx<tx   && hy<ty-1)   map[hx + 1][hy + 2] = -1;
	if (hx<tx-1 && hy<ty  )   map[hx + 2][hy + 1] = -1;
	
	map[hx][hy] = -1; //马
	
	for (int x = 0; x <= tx; x++) { 
		if (map[x][0] < 0)break;
		map[x][0] = 1; 
	}
	for (int y = 0; y <= ty; y++) { 
		if (map[0][y] < 0)break;
		map[0][y] = 1; 
	}

	for (int x = 1; x <= tx; x++) {
		for (int y = 1; y <= ty; y++) {
			if (map[x][y] < 0)continue;
			int l = map[x - 1][y];
			int u = map[x][y - 1];
			map[x][y] = l + u + (l < 0) + (u < 0);
		}
	}

	if(map[tx][ty]>=0)cout << map[tx][ty] << endl;
	else { cout << 0 << endl; }
	return 0;
}

int main(){
    P1002();
    return 0;
}
2022/3/31 13:38
加载中...