회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
킹 문제.. 질문입니다. 반례를 못찾겠어요
1063번 - 킹
gkagm2
3년 전
0
반례를 못찾겠네요
#include <iostream> #include <string> #define MAX_MAP_SIZE 8 using namespace std; struct Vector2 { int x; int y; Vector2() : x(0), y(0){} Vector2 operator +(const Vector2 *vec) { Vector2 tempVec; tempVec.x += vec->x; tempVec.y += vec->y; return tempVec; } }; bool Move(const string &_move, Vector2 & _position) { Vector2 direction; for (unsigned i = 0; i < _move.size(); ++i) { if (_move[i] == 'R') direction.x += 1; else if (_move[i] == 'L') direction.x -= 1; else if (_move[i] == 'T') direction.y -= 1; else if (_move[i] == 'B') direction.y += 1; } Vector2 position; position.x = _position.x + direction.x; position.y = _position.y + direction.y; if (position.x < 0 || position.y < 0 || position.x >= MAX_MAP_SIZE || position.y >= MAX_MAP_SIZE) return false; _position = position; return true; } void PositionSetting(string _strPos, Vector2 &_pos) { _pos.x = _strPos[0] - 'A'; _pos.y = MAX_MAP_SIZE - (_strPos[1] - '0'); } void PrintPosition(Vector2 _pos) { char x = _pos.x + 'A'; char y = MAX_MAP_SIZE - _pos.y + '0'; cout << x << y << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Vector2 kingPos; Vector2 stonePos; string strStartPos[2]; int n; cin >> strStartPos[0] >> strStartPos[1] >> n; PositionSetting(strStartPos[0], kingPos); PositionSetting(strStartPos[1], stonePos); for (int i = 0; i < n; ++i) { string commend; cin >> commend; Vector2 tempKingPos = kingPos; Vector2 tempStonePos = stonePos; bool isPosibleToMove = false; if (Move(commend, tempKingPos) && Move(commend, tempStonePos)) isPosibleToMove = true; if (isPosibleToMove) { kingPos = tempKingPos; stonePos = tempStonePos; } } PrintPosition(kingPos); PrintPosition(stonePos); return 0; }
댓글을 작성하려면
로그인
해야 합니다.
gkagm2 3년 전
반례를 못찾겠네요