Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

24-seongwon030 #88

Merged
merged 2 commits into from
Aug 21, 2024
Merged

24-seongwon030 #88

merged 2 commits into from
Aug 21, 2024

Conversation

seongwon030
Copy link
Collaborator

@seongwon030 seongwon030 commented Aug 10, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

์ฃผ์‚ฌ์œ„๊ตด๋ฆฌ๊ธฐ

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

4์‹œ๊ฐ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

์˜ค๋žœ๋งŒ์— ๊ตฌํ˜„๋ฌธ์ œ๋ฅผ ํ’€์–ด๋ดค์Šต๋‹ˆ๋‹ค. ์ฃผ์‚ฌ์œ„ ๊ตฌํ˜„์—์„œ ๋จธ๋ฆฌ๊ฐ€ .. ์•„ํŒ ์ง€๋งŒ ์–ด์ฐŒ์ €์ฐŒ ํ’€์—ˆ์Šต๋‹ˆ๋‹ค.

์ฃผ์‚ฌ์œ„

์ฃผ์‚ฌ์œ„ ์ „๊ฐœ๋„๋ฅผ ํ† ๋Œ€๋กœ ์ฃผ์‚ฌ์œ„ ์ธ๋ฑ์Šค ์ˆœ์„œ๋ฅผ ์™ผ์ชฝ์˜†๋ฉด - ๋ถ์ชฝ๋ฉด - ์œ—๋ฉด - ์˜ค๋ฅธ์ชฝ์˜†๋ฉด - ๋‚จ์ชฝ๋ฉด - ์•„๋žซ๋ฉด์„ ์ˆœ์„œ๋กœ ๊ฐ€์ •ํ–ˆ๋‹ค.

dice = [0]*6

๋จผ์ € ์ฃผ์‚ฌ์œ„๊ฐ€ ๋™/์„œ๋กœ ๊ตด๋Ÿฌ๊ฐˆ ๋•Œ์™€ ๋ถ/๋‚จ์œผ๋กœ ๊ตด๋Ÿฌ๊ฐˆ ๋•Œ๋ฅผ ๋ถ„๋ฆฌํ•ด์„œ ์ƒ๊ฐํ•ด๋ดค๋‹ค.

๋™์ชฝ์œผ๋กœ ๊ตด๋Ÿฌ๊ฐˆ ๋•Œ

์ฃผ์‚ฌ์œ„ ๋ถ์ชฝ๋ฉด๊ณผ ๋‚จ์ชฝ๋ฉด์€ ๋ณ€ํ•˜์ง€ ์•Š๋Š”๋‹ค.
์˜ค๋ฅธ์ชฝ์œผ๋กœ ๊ตด๋Ÿฌ๊ฐˆ๋•Œ ์ฃผ์‚ฌ์œ„์˜ ์ˆซ์ž๋“ค์€ ์„œ->๋™ ์œผ๋กœ ํ•œ ์นธ์”ฉ ์ด๋™ํ•˜๊ฒŒ ๋œ๋‹ค.
๋ฆฌ์ŠคํŠธ์˜ ์ด์ „ ์ธ๋ฑ์Šค์˜ ์ˆซ์ž๋กœ ๋ชจ๋“  ์ธ๋ฑ์Šค๋ฅผ ๋ฐ”๊ฟ”์ค€๋‹ค.

 dice[0],dice[2],dice[3],dice[5] =  dice[5],dice[0],dice[2],dice[3]

์„œ์ชฝ์€ ๋ฐ˜๋Œ€๋กœ ์ƒ๊ฐํ•œ๋‹ค.

๋ถ์ชฝ์œผ๋กœ ๊ตด๋Ÿฌ๊ฐˆ ๋•Œ

์ฃผ์‚ฌ์œ„์˜ ์™ผ์ชฝ ์˜†๋ฉด๊ณผ ์˜ค๋ฅธ์ชฝ ์˜†๋ฉด์€ ๋ณ€ํ•˜์ง€ ์•Š๋Š”๋‹ค.
๋ถ์ชฝ์œผ๋กœ ๊ตด๋Ÿฌ๊ฐˆ๋•Œ ์ฃผ์‚ฌ์œ„์˜ ์ˆซ์ž๋“ค์€ ๋‚จ->๋ถ ์œผ๋กœ ํ•œ ์นธ์”ฉ ์ด๋™ํ•˜๊ฒŒ ๋œ๋‹ค.

dice[1],dice[2],dice[4],dice[5] = dice[2],dice[4],dice[5],dice[1]

๋‚จ์ชฝ ๋˜ํ•œ ๋ฐ˜๋Œ€๋กœ ์ƒ๊ฐํ•œ๋‹ค.

์กฐ๊ฑด

  1. ์ฃผ์‚ฌ์œ„๊ฐ€ ์›€์ง์ผ ๋•Œ๋งˆ๋‹ค ์ด๋™ ํ›„์˜ ์ขŒํ‘œ๊ฐ€ ์œ ํšจํ•œ์ง€ ๊ฒ€์‚ฌํ•œ๋‹ค.
  2. ๋งŒ์•ฝ ์ขŒํ‘œ์— ํ•ด๋‹นํ•˜๋Š” ์ˆ˜๊ฐ€ 0์ด๋ฉด ์ฃผ์‚ฌ์œ„ ์•„๋žซ๋ฉด์˜ ์ˆซ์ž๋ฅผ ๋ณต์‚ฌํ•œ๋‹ค.
  3. 0์ด ์•„๋‹ˆ๋ฉด ๊ทธ ์ˆซ์ž๋ฅผ ์ฃผ์‚ฌ์œ„ ์•„๋žซ๋ฉด์— ๋ณต์‚ฌํ•˜๊ณ  ์ขŒํ‘œ์˜ ์ˆซ์ž๋ฅผ 0์œผ๋กœ ๋ฐ”๊พธ์–ด์ค€๋‹ค.
  4. ์›€์ง์ผ ๋•Œ๋งˆ๋‹ค ์ฃผ์‚ฌ์œ„ ์œ—๋ฉด์— ํ•ด๋‹นํ•˜๋Š” ์ˆซ์ž๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

์ „์ฒด์ฝ”๋“œ

import sys
input = sys.stdin.readline

n,m,x,y,k = map(int,input().split())
arr = []
for _ in range(n):
  arr.append(list(map(int,input().split())))

move = list(map(int,input().split()))

# ์ฃผ์‚ฌ์œ„ (์„œ,๋ถ,์œ—๋ฉด,์˜ค,๋‚จ,์•„๋žซ๋ฉด) ์ดˆ๊ธฐ๊ฐ’
dice = [0]*6

for i in move:
  if i == 1: # ๋™ 
    if y+1 < m:
      y+=1
      dice[0],dice[2],dice[3],dice[5] =  dice[5],dice[0],dice[2],dice[3]
      print(dice[2])
      if arr[x][y] == 0:
        arr[x][y] = dice[5]
      else:
        dice[5] = arr[x][y]
        arr[x][y] = 0
  elif i == 2: # ์„œ
    if y-1 >=0:
      y-=1
      dice[0],dice[2],dice[3],dice[5] = dice[2],dice[3],dice[5],dice[0]
      print(dice[2])
      if arr[x][y] == 0:
        arr[x][y] = dice[5]
      else:
        dice[5] = arr[x][y]
        arr[x][y] = 0
  elif i == 3: # ๋ถ
    if x-1 >=0:
      x-=1
      dice[1],dice[2],dice[4],dice[5] = dice[2],dice[4],dice[5],dice[1]
      print(dice[2])
      if arr[x][y] == 0:
        arr[x][y] = dice[5]
      else:
        dice[5] = arr[x][y]
        arr[x][y] = 0
  elif i == 4: # ๋‚จ
    if x+1 < n:
      x+=1
      dice[1],dice[2],dice[4],dice[5] = dice[5],dice[1],dice[2],dice[4]
      print(dice[2])
      if arr[x][y] == 0:
        arr[x][y] = dice[5]
      else:
        dice[5] = arr[x][y]
        arr[x][y] = 0

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

๋งˆ์ง€๋ง‰ ์กฐ๊ฑด์— 0์œผ๋กœ ๋ฐ”๊พธ์–ด์ฃผ์ง€ ์•Š์•„ 1์‹œ๊ฐ„์„ ๋” ์ผ์Šต๋‹ˆ๋‹ค. ๋ฌธ์ œ๋ฅผ ์ž˜ ์ฝ์–ด์•ผ ํ•˜๋Š”๋ฐ ํ•˜ํ•˜.. ์˜ค๋žœ๋งŒ์˜ ๊ตฌํ˜„๋ฌธ์ œ ์—ญ์‹œ ์žฌ๋ฐŒ๋„ค์š”.

Copy link
Collaborator

@InSange InSange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ฃผ์‚ฌ์œ„๊ฐ€ ๊ตด๋ ค์งˆ ๋•Œ ๋งˆ๋‹ค ๊ตด๋ ค์ง€๋Š” ๋ฐฉํ–ฅ๋ณ„๋กœ ๊ฐ๊ฐ ๋ฉด์— ๋Œ€ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์—…๋ฐ์ดํŠธ ํ•ด์ฃผ๋Š” ๋ฐฉ์‹ ์ž˜ ๋ดค์Šต๋‹ˆ๋‹ค. ๋จธ๋ฆฌ๋กœ ์ดํ•ดํ•  ๋•Œ๋งŒ ํ•ด๋„ ์ฃผ์‚ฌ์œ„ ๋ฐฉ๋ฉด์„ ์ฒดํฌํ•ด์ค„ ๋•Œ ๋งˆ๋‹ค ๊ณ ์—ญ์ด์˜€๋Š”๋ฐ ์ฝ”๋“œ๋ฅผ ์งœ๊ณ  ๋ณด๋ฉด ๋˜๊ฒŒ ๊ฐ„ํŽธํ•˜๋„ค์š”..!

Copy link
Member

@tgyuuAn tgyuuAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n, m, x, y, k = map(int, input().split())

board = []
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]
dice = [0, 0, 0, 0, 0, 0]

def turn(dir):
    a, b, c, d, e, f = dice[0], dice[1], dice[2], dice[3], dice[4], dice[5]
    if dir == 1: #๋™
        dice[0], dice[1], dice[2], dice[3], dice[4], dice[5] = d, b, a, f, e, c

    elif dir == 2: #์„œ
        dice[0], dice[1], dice[2], dice[3], dice[4], dice[5] = c, b, f, a, e, d

    elif dir == 3: #๋ถ
        dice[0], dice[1], dice[2], dice[3], dice[4], dice[5] = e, a, c, d, f, b

    else:
        dice[0], dice[1], dice[2], dice[3], dice[4], dice[5] = b, f, c, d, a, e

for i in range(n):
    board.append(list(map(int, input().split())))

comm = list(map(int, input().split()))

nx, ny = x, y
for i in comm:
    nx += dx[i-1]
    ny += dy[i-1]

    if nx < 0 or nx >= n or ny < 0 or ny >= m:
        nx -= dx[i-1]
        ny -= dy[i-1]
        continue
    turn(i)
    if board[nx][ny] == 0:
        board[nx][ny] = dice[-1]
    else:
        dice[-1] = board[nx][ny]
        board[nx][ny] = 0

    print(dice[0])

์•„์˜ค ์ด ๊ฑฐ ๋ฌธ์ œ ํ’€๋‹ค๊ฐ€ ๋ฌธ์ œ๋ฅผ ์ž˜๋ชป ์ฝ์–ด์„œ 3์‹œ๊ฐ„ ๋‚ ๋ฆฌ๊ณ  ๊ทธ๋ƒฅ ๋ฝ์ด ์ณ๋ฒ„๋ ค์„œ ์„œ์นญํ•ด์„œ ๋ ˆํผ๋Ÿฐ์Šค ๋ณด๊ณ  ํ’€์—ˆ์Šต๋‹ˆ๋‹ค.

์•„์˜ค!!!!!!!!!!!!!!!!!!!!!!!!!!

์ €๋Š” ์ฒ˜์Œ์— ๋‹ค 0์œผ๋กœ ์ดˆ๊ธฐํ™”๋˜์–ด์žˆ๋Š”๋ฐ, ์œ—๋ฉด์ด 1์ด๊ณ  ๋™์ชฝ๋ฉด์ด 3์ธ์ฑ„๋กœ ์‹œ์ž‘ํ•˜๋Š” ์ค„ ์•Œ์•˜์–ด์š”.

ํ•˜ ;;;;;;;;;;

@seongwon030
Copy link
Collaborator Author

์ €๋„ ์ฃผ์‚ฌ์œ„ ์ „๊ฐœ๋„ ๋•œ์— ์ดํ•ดํ•˜๋Š”๋ฐ ๋งŽ์ด ๊ฑธ๋ ธ์Šต๋‹ˆ๋‹ค. ๋™์„œ๋‚จ๋ถ ๋ฐฉํ–ฅ์„ ๋จผ์ € ์ž˜ ์žก๊ณ  ๊ฐ€์•ผ ํ•˜๋”๋ผ๊ณ ์š”.

์ŠคํŠธ๋ ˆ์Šค ๋งŒ๋•…์ธ ๋ฌธ์ œ์˜€์Šต๋‹ˆ๋‹ค! ใ…‹ใ…‹ใ…‹

Copy link

@H0ngJu H0ngJu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ตฌํ˜„๋ฌธ์ œ .. ์žฌ๋ฐŒ๋„ค์š” ํ—ˆํ—ˆ
๋ฌธ์ œ์—์„œ ์š”๊ตฌํ•˜๋Š”๋Œ€๋กœ ๋”ฐ๋ผ๊ฐ€๋ฉด์„œ ํ’€์—ˆ๋Š”๋ฐ..
์ฃผ์‚ฌ์œ„ ๊ตด๋ฆฌ๋Š” ๋ถ€๋ถ„์—์„œ index ์˜คํƒ€ 1๊ฐœ ๋•Œ๋ฌธ์— 40๋ถ„๋™์•ˆ ์ณ๋‹ค๋ณด๊ณ  ์žˆ์—ˆ๋„ค์š” ..ใ…‹.ใ…‹..ใ…‹ใ…‹.ใ…‹.ใ…‹..ใ…‹.ใ…‹ใ…‹.ใ…‹..ใ…‹.ใ…‹

๊ฐ„๋งŒ์— ์žฌ๋ฐŒ๋Š” ๋ฌธ์ œ ์ž˜ ํ’€์—ˆ์Šต๋‹ˆ๋‹ค ~~

import sys

def input() : return sys.stdin.readline().rstrip()

N, M, x, y, K = map(int, input().split())
board = [[] for _ in range(N)]
dice = [0 for _ in range(6)]
cmd = []
for i in range(N):
    board[i].extend(list(map(int, input().split())))
cmd.extend(map(int, input().split()))

def check(x, y):
    if x < 0 or y < 0 or y >= M or x >= N:
        return False
    return True

def roll(n):
    if n == 1:
        dice[0], dice[2], dice[3], dice[5] = dice[2], dice[5], dice[0], dice[3]
    elif n == 2:
        dice[0], dice[2], dice[3], dice[5] = dice[3], dice[0], dice[5], dice[2]
    elif n == 3:
        dice[0], dice[1], dice[4], dice[5] = dice[4], dice[0], dice[5], dice[1]
    else:
        dice[0], dice[1], dice[4], dice[5] = dice[1], dice[5], dice[0], dice[4]


def copy(x, y):
    if board[x][y] == 0:
        board[x][y] = dice[5]
    else:
        dice[5] = board[x][y]
        board[x][y] = 0
        

# ๋™ 1 ์„œ 2 ๋ถ 3 ๋‚จ 4
dic_x, dic_y = x,y # ์ฃผ์‚ฌ์œ„ ์œ„์น˜ ์ดˆ๊ธฐํ™”
#print(dice)

for i in range(len(cmd)):
    nx, ny = dic_x, dic_y
    # ์ผ๋‹จ ํ•ด๋‹น ์œ„์น˜๋กœ ์ด๋™
    if cmd[i] == 1:
        ny += 1
    elif cmd[i] == 2:
        ny -= 1
    elif cmd[i] == 3:
        nx -= 1
    elif cmd[i] == 4:
        nx += 1
    else: continue

    if check(nx, ny):
        dic_x, dic_y = nx, ny
        roll(cmd[i])
        copy(dic_x, dic_y)
        #print(dice)
        print(dice[0])

Copy link
Collaborator

@yuyu0830 yuyu0830 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•„๋‹ˆ ์ด๊ฑธ ์ด๋ ‡๊ฒŒ ์ผ์ผ์ด ๋‹ค ์›€์ง์ž„์„ ๊ตฌํ˜„ํ•ด์„œ ํ’€์–ด ใ…‹ใ…‹ใ…‹ ์‹ถ์—ˆ๋Š”๋ฐ ์˜ˆ์ „์— ํ‘ผ ์ œ ํ’€์ด๋ฅผ ๋ณด๋‹ˆ ์ด๊ฒŒ ์ •๋ฐฐ์ธ ๊ฒƒ ๊ฐ™๋„ค์š” ใ…Žใ…Ž

์ด๋Ÿฐ ๊ตฌํ˜„ ๋ฌธ์ œ๊ฐ€ ์ฝ”๋“œ ์ž‘์„ฑ์€ ์กฐ๊ธˆ ๋จธ๋ฆฌ์•„ํ”„๊ธด ํ•ด๋„ ํ‘ธ๋Š” ์žฌ๋ฏธ๊ฐ€ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์•„์š” ใ…Žใ…Ž

#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;

enum dir {
	NONE,
	RIGHT,
	LEFT,
	FRONT,
	BACK
};

const int DIR[5][2] = {
	{ 0, 0 },
	{ 0, 1 },
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 }
	};

struct dice {
	int up = 0;
	int front = 0;
	int back = 0;
	int down = 0;
	int right = 0;
	int left = 0;
};

void moveDice(dice &d, int dir) {
	int tUp, tFront, tBack, tDown, tRight, tLeft;
	if (dir == FRONT) {
		tRight = d.right;
		tLeft = d.left;
		tFront = d.up;
		tDown = d.front;
		tBack = d.down;
		tUp = d.back;
	}
	else if (dir == RIGHT) {
		tFront = d.front;
		tBack = d.back;
		tRight = d.up;
		tDown = d.right;
		tLeft = d.down;
		tUp = d.left;
	}
	else if (dir == BACK) {
		tRight = d.right;
		tLeft = d.left;
		tFront = d.down;
		tDown = d.back;
		tBack = d.up;
		tUp = d.front;
	}
	else {
		tFront = d.front;
		tBack = d.back;
		tRight = d.down;
		tDown = d.left;
		tLeft = d.up;
		tUp = d.right;
	}
	d.right = tRight;
	d.left = tLeft;
	d.front = tFront;
	d.down = tDown;
	d.back = tBack;
	d.up = tUp;
}

void printDice(dice d) {
	printf("0 %d 0\n", d.front);
	printf("%d %d %d\n", d.left, d.up, d.right);
	printf("0 %d 0\n", d.back);
	printf("0 %d 0\n\n", d.down);
}

bool isn(int t, int a, int b) {
	if (t >= a && t < b) return true;
	return false;
}

dice d;
int arr[21][21] = { 0, };
int dicePos[2] = { 0, 0 };
int n;

int main() {
	int x, y, a;
	cin >> x >> y >> dicePos[0] >> dicePos[1] >> n;
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			cin >> arr[i][j];
		}
	}

	while (n--) {
		cin >> a;
		if (isn(dicePos[0] + DIR[a][0], 0, x) && isn(dicePos[1] + DIR[a][1], 0, y)) {
			dicePos[0] += DIR[a][0];
			dicePos[1] += DIR[a][1];
			moveDice(d, a);
			if (arr[dicePos[0]][dicePos[1]]) {
				d.down = arr[dicePos[0]][dicePos[1]];
				arr[dicePos[0]][dicePos[1]] = 0;
			}
			else {
				arr[dicePos[0]][dicePos[1]] = d.down;
			}
			printf("%d\n", d.up);
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants