Atcoder ABC273_D样例没过,求助!
  • 板块题目总版
  • 楼主ZZWX_luogu
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/3/27 20:13
  • 上次更新2023/10/23 20:17:53
查看原帖
Atcoder ABC273_D样例没过,求助!
679473
ZZWX_luogu楼主2023/3/27 20:13

输入如洛谷题目的样例1,我的输出如下:

1 3
3 3 
3 1
3 5

代码如下:

#include <iostream>
#include <map>
using namespace std;

//L==>左,R==>右,U==>前,D==>后
map<int, pair<bool/*have*/, int/*at*/>> L, R, U, D;

int n, m, e, x, y, q;
int main() {
	int x, y;
	scanf("%d%d%d%d%d", &n, &m, &x, &y, &e);
	while (e--) {
		scanf("%d%d", &x, &y);
		if (!L[x].first || L[x].second > y) L[x].first = true, L[x].second = y;
		if (!R[x].first || R[x].second < y) R[x].first = true, R[x].second = y;
		if (!U[y].first || U[y].second < x) U[y].first = true, U[y].second = x;
		if (!D[y].first || D[y].second > x) D[y].first = true, D[y].second = x;
	}
	scanf("%d", &q);
	getchar();
	while (q--) {
		char move;
		int v;
		scanf("%c%d", &move, &v);
		getchar();
		if (move == 'L') {
			if (L[x].first && L[x].second >= y - v) y = L[x].second + 1;
			if (y - v < 1) y = 1;
			else y -= v;
		}
		else if (move == 'R') {
			if (R[x].first && R[x].second <= y + v) y = R[x].second - 1;
			if (y + v > n) y = n;
			else y += v;
		}
		else if (move == 'U') {
			if (U[y].first && U[y].second >= x - v) x = U[y].second + 1;
			if (x - v < 1) x = 1;
			else x -= v;
		}
		else if (move == 'D') {
			if (D[y].first && D[y].second <= x + v) x = D[y].second - 1;
			if (x + v > m) x = m;
			else x += v;
		}
		else exit(-1);
		printf("%d %d\n", x, y);
	}
	return 0;
}

请大佬指导!

2023/3/27 20:13
加载中...