๐Ÿ™‡โ€โ™€๏ธ[Silver III] ํ‚น - 1063

๋ฌธ์ œ ๋งํฌ

์„ฑ๋Šฅ ์š”์•ฝ

๋ฉ”๋ชจ๋ฆฌ: 2032 KB, ์‹œ๊ฐ„: 0 ms

๋ถ„๋ฅ˜

๊ตฌํ˜„, ์‹œ๋ฎฌ๋ ˆ์ด์…˜

์ œ์ถœ ์ผ์ž

2024๋…„ 2์›” 28์ผ 21:25:33

๋ฌธ์ œ ์„ค๋ช…

8*8ํฌ๊ธฐ์˜ ์ฒด์ŠคํŒ์— ์™•์ด ํ•˜๋‚˜ ์žˆ๋‹ค. ํ‚น์˜ ํ˜„์žฌ ์œ„์น˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ฒด์ŠคํŒ์—์„œ ๋ง์˜ ์œ„์น˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฃผ์–ด์ง„๋‹ค. ์•ŒํŒŒ๋ฒณ ํ•˜๋‚˜์™€ ์ˆซ์ž ํ•˜๋‚˜๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋Š”๋ฐ, ์•ŒํŒŒ๋ฒณ์€ ์—ด์„ ์ƒ์ง•ํ•˜๊ณ , ์ˆซ์ž๋Š” ํ–‰์„ ์ƒ์ง•ํ•œ๋‹ค. ์—ด์€ ๊ฐ€์žฅ ์™ผ์ชฝ ์—ด์ด A์ด๊ณ , ๊ฐ€์žฅ ์˜ค๋ฅธ์ชฝ ์—ด์ด H๊นŒ์ง€ ์ด๊ณ , ํ–‰์€ ๊ฐ€์žฅ ์•„๋ž˜๊ฐ€ 1์ด๊ณ  ๊ฐ€์žฅ ์œ„๊ฐ€ 8์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์™ผ์ชฝ ์•„๋ž˜ ์ฝ”๋„ˆ๋Š” A1์ด๊ณ , ๊ทธ ์˜ค๋ฅธ์ชฝ ์นธ์€ B1์ด๋‹ค.

ํ‚น์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์›€์ง์ผ ์ˆ˜ ์žˆ๋‹ค.

  • R : ํ•œ ์นธ ์˜ค๋ฅธ์ชฝ์œผ๋กœ
  • L : ํ•œ ์นธ ์™ผ์ชฝ์œผ๋กœ
  • B : ํ•œ ์นธ ์•„๋ž˜๋กœ
  • T : ํ•œ ์นธ ์œ„๋กœ
  • RT : ์˜ค๋ฅธ์ชฝ ์œ„ ๋Œ€๊ฐ์„ ์œผ๋กœ
  • LT : ์™ผ์ชฝ ์œ„ ๋Œ€๊ฐ์„ ์œผ๋กœ
  • RB : ์˜ค๋ฅธ์ชฝ ์•„๋ž˜ ๋Œ€๊ฐ์„ ์œผ๋กœ
  • LB : ์™ผ์ชฝ ์•„๋ž˜ ๋Œ€๊ฐ์„ ์œผ๋กœ

์ฒด์ŠคํŒ์—๋Š” ๋Œ์ด ํ•˜๋‚˜ ์žˆ๋Š”๋ฐ, ๋Œ๊ณผ ๊ฐ™์€ ๊ณณ์œผ๋กœ ์ด๋™ํ•  ๋•Œ๋Š”, ๋Œ์„ ํ‚น์ด ์›€์ง์ธ ๋ฐฉํ–ฅ๊ณผ ๊ฐ™์€ ๋ฐฉํ–ฅ์œผ๋กœ ํ•œ ์นธ ์ด๋™์‹œํ‚จ๋‹ค. ์•„๋ž˜ ๊ทธ๋ฆผ์„ ์ฐธ๊ณ ํ•˜์ž.

์ž…๋ ฅ์œผ๋กœ ํ‚น์ด ์–ด๋–ป๊ฒŒ ์›€์ง์—ฌ์•ผ ํ•˜๋Š”์ง€ ์ฃผ์–ด์ง„๋‹ค. ์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง„ ๋Œ€๋กœ ์›€์ง์—ฌ์„œ ํ‚น์ด๋‚˜ ๋Œ์ด ์ฒด์ŠคํŒ ๋ฐ–์œผ๋กœ ๋‚˜๊ฐˆ ๊ฒฝ์šฐ์—๋Š” ๊ทธ ์ด๋™์€ ๊ฑด๋„ˆ ๋›ฐ๊ณ  ๋‹ค์Œ ์ด๋™์„ ํ•œ๋‹ค.

ํ‚น๊ณผ ๋Œ์˜ ๋งˆ์ง€๋ง‰ ์œ„์น˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ํ‚น์˜ ์œ„์น˜, ๋Œ์˜ ์œ„์น˜, ์›€์ง์ด๋Š” ํšŸ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ํ‚น์ด ์–ด๋–ป๊ฒŒ ์›€์ง์—ฌ์•ผ ํ•˜๋Š”์ง€ ์ฃผ์–ด์ง„๋‹ค. N์€ 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๊ณ , ์›€์ง์ด๋Š” ์ •๋ณด๋Š” ์œ„์— ์“ฐ์—ฌ ์žˆ๋Š” 8๊ฐ€์ง€ ์ค‘ ํ•˜๋‚˜์ด๋‹ค.

์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— ํ‚น์˜ ๋งˆ์ง€๋ง‰ ์œ„์น˜, ๋‘˜์งธ ์ค„์— ๋Œ์˜ ๋งˆ์ง€๋ง‰ ์œ„์น˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

๐Ÿš€ํ’€์ด

map์„ ์ด์šฉํ•ด์„œ ์ž…๋ ฅ๊ฐ’์˜ ์ธ๋ฑ์Šค๋ฅผ ๋ฐ”๋กœ ๋„˜๊ฒจ์ค˜์„œ ํ’€์—ˆ๋‹ค.
์ธ๋ฑ์Šค๋Š” dy, dx์˜ ์ธ๋ฑ์Šค์ธ๋ฐ ์ž…๋ ฅ๊ฐ’๊ณผ ๋™์ผํ•œ ์ˆœ์„œ๋กœ ๋งŒ๋“ค์—ˆ๋‹ค.
ํ–‰์˜ ๊ฒฝ์šฐ ๋ฐ‘์—์„œ๋ถ€ํ„ฐ 1~8 ์ด๊ธฐ ๋•Œ๋ฌธ์— ์•ฝ๊ฐ„์˜ ๋ณ€ํ™”๋ฅผ ์ฃผ์—ˆ๋‹ค.

์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด ๋” ์‰ฌ์›€.

/*

R : ํ•œ ์นธ ์˜ค๋ฅธ์ชฝ์œผ๋กœ
L : ํ•œ ์นธ ์™ผ์ชฝ์œผ๋กœ
B : ํ•œ ์นธ ์•„๋ž˜๋กœ
T : ํ•œ ์นธ ์œ„๋กœ
RT : ์˜ค๋ฅธ์ชฝ ์œ„ ๋Œ€๊ฐ์„ ์œผ๋กœ
LT : ์™ผ์ชฝ ์œ„ ๋Œ€๊ฐ์„ ์œผ๋กœ
RB : ์˜ค๋ฅธ์ชฝ ์•„๋ž˜ ๋Œ€๊ฐ์„ ์œผ๋กœ
LB : ์™ผ์ชฝ ์•„๋ž˜ ๋Œ€๊ฐ์„ ์œผ๋กœ

*/

// ์œ„์˜ ์ˆœ์„œ๋Œ€๋กœ ๋งŒ๋“ฆ.
int n;
int board[10][10];
int dy[] = { 0, 0, 1, -1, -1, -1, 1, 1 };
int dx[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
map<string, int> m =
{
	{"R", 0},
	{"L", 1},
	{"B", 2},
	{"T", 3},
	{"RT", 4},
	{"LT", 5},
	{"RB", 6},
	{"LB", 7},
};
void solve()
{
	string kingPos, piecePos;
	pair<int, int> king, piece;
	cin >> kingPos >> piecePos >> n;

	int y = abs(8 - (kingPos[1] - '1' + 1)) + 1;
	int x = kingPos[0] - 'A' + 1;
	king = { y , x };

	y = abs(8 - (piecePos[1] - '1' + 1)) + 1;
	x = piecePos[0] - 'A' + 1;
	piece = { y , x };

	// n๋ฒˆ ์ด๋™
	string moveStr;
	for (int i = 0; i < n; ++i)
	{
		cin >> moveStr;
		int ny = king.first + dy[m[moveStr]];
		int nx = king.second + dx[m[moveStr]];

		if (ny < 1 || nx < 1 || ny > 8 || nx > 8)
			continue;
		if (ny == piece. first && nx == piece.second)
		{
			int pny = piece.first + dy[m[moveStr]];
			int pnx = piece.second + dx[m[moveStr]];

			if (pny < 1 || pnx < 1 || pny > 8 || pnx > 8)
				continue;
			piece.first = pny;
			piece.second = pnx;
		}

		king.first = ny;
		king.second = nx;
	}

	// ๋งˆ์ง€๋ง‰ ์œ„์น˜ ์ถœ๋ ฅ
	char kingY = abs('8' - king.first) + 1;
	char kingX = king.second + 'A' - 1;
	cout << kingX << kingY << '\n';

	char pieceY = abs('8' - piece.first) + 1;
	char pieceX = piece.second + 'A' - 1;
	cout << pieceX << pieceY << '\n';
}

์˜ค๋žœ๋งŒ์— ์‹ค๋ฒ„๋ฌธ์ œ๋ฅผ ํ‘ธ๋‹ˆ ์‚ด๊ฑฐ๊ฐ™๋‹ค..

๊ทผ๋ฐ ๊ทธ๋ž˜๋„ ์‹ค3๋ฌธ์  ๋ฐ ๋ ˆ์ดํŒ…์„ ํ•˜๋‚˜๋„ ์•ˆ์ฃผ๋Š”๊ฑด ๋„ˆ๋ฌดํ•œ๋ฐ.. ใ… 

๐Ÿš€์ „์ฒด ์ฝ”๋“œ

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include<iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>

using namespace std;


/*

R : ํ•œ ์นธ ์˜ค๋ฅธ์ชฝ์œผ๋กœ
L : ํ•œ ์นธ ์™ผ์ชฝ์œผ๋กœ
B : ํ•œ ์นธ ์•„๋ž˜๋กœ
T : ํ•œ ์นธ ์œ„๋กœ
RT : ์˜ค๋ฅธ์ชฝ ์œ„ ๋Œ€๊ฐ์„ ์œผ๋กœ
LT : ์™ผ์ชฝ ์œ„ ๋Œ€๊ฐ์„ ์œผ๋กœ
RB : ์˜ค๋ฅธ์ชฝ ์•„๋ž˜ ๋Œ€๊ฐ์„ ์œผ๋กœ
LB : ์™ผ์ชฝ ์•„๋ž˜ ๋Œ€๊ฐ์„ ์œผ๋กœ

*/

// ์œ„์˜ ์ˆœ์„œ๋Œ€๋กœ ๋งŒ๋“ฆ.
int n;
int board[10][10];
int dy[] = { 0, 0, 1, -1, -1, -1, 1, 1 };
int dx[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
map<string, int> m =
{
	{"R", 0},
	{"L", 1},
	{"B", 2},
	{"T", 3},
	{"RT", 4},
	{"LT", 5},
	{"RB", 6},
	{"LB", 7},
};
void solve()
{
	string kingPos, piecePos;
	pair<int, int> king, piece;
	cin >> kingPos >> piecePos >> n;

	int y = abs(8 - (kingPos[1] - '1' + 1)) + 1;
	int x = kingPos[0] - 'A' + 1;
	king = { y , x };

	y = abs(8 - (piecePos[1] - '1' + 1)) + 1;
	x = piecePos[0] - 'A' + 1;
	piece = { y , x };

	// n๋ฒˆ ์ด๋™
	string moveStr;
	for (int i = 0; i < n; ++i)
	{
		cin >> moveStr;
		int ny = king.first + dy[m[moveStr]];
		int nx = king.second + dx[m[moveStr]];

		if (ny < 1 || nx < 1 || ny > 8 || nx > 8)
			continue;
		if (ny == piece. first && nx == piece.second)
		{
			int pny = piece.first + dy[m[moveStr]];
			int pnx = piece.second + dx[m[moveStr]];

			if (pny < 1 || pnx < 1 || pny > 8 || pnx > 8)
				continue;
			piece.first = pny;
			piece.second = pnx;
		}

		king.first = ny;
		king.second = nx;
	}

	// ๋งˆ์ง€๋ง‰ ์œ„์น˜ ์ถœ๋ ฅ
	char kingY = abs('8' - king.first) + 1;
	char kingX = king.second + 'A' - 1;
	cout << kingX << kingY << '\n';

	char pieceY = abs('8' - piece.first) + 1;
	char pieceX = piece.second + 'A' - 1;
	cout << pieceX << pieceY << '\n';
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	freopen("input.txt", "rt", stdin);

	solve();

	return 0;
}

ํƒœ๊ทธ:

์นดํ…Œ๊ณ ๋ฆฌ:

์—…๋ฐ์ดํŠธ: