|
3 | 3 | { |
4 | 4 | "cell_type": "code", |
5 | 5 | "execution_count": 4, |
6 | | - "id": "79c55f83", |
| 6 | + "id": "b54eeae6", |
7 | 7 | "metadata": {}, |
8 | 8 | "outputs": [ |
9 | 9 | { |
|
47 | 47 | { |
48 | 48 | "cell_type": "code", |
49 | 49 | "execution_count": 8, |
50 | | - "id": "e2cad454", |
| 50 | + "id": "2acfdb9f", |
51 | 51 | "metadata": {}, |
52 | 52 | "outputs": [ |
53 | 53 | { |
|
90 | 90 | "print(sol(n))" |
91 | 91 | ] |
92 | 92 | }, |
| 93 | + { |
| 94 | + "cell_type": "code", |
| 95 | + "execution_count": 26, |
| 96 | + "id": "f10f2d54", |
| 97 | + "metadata": {}, |
| 98 | + "outputs": [ |
| 99 | + { |
| 100 | + "name": "stdout", |
| 101 | + "output_type": "stream", |
| 102 | + "text": [ |
| 103 | + "c2\n", |
| 104 | + "1 2\n", |
| 105 | + "ny : 2 nx : 4\n", |
| 106 | + "ny : 0 nx : 4\n", |
| 107 | + "ny : 2 nx : 0\n", |
| 108 | + "ny : 0 nx : 0\n", |
| 109 | + "ny : 3 nx : 3\n", |
| 110 | + "ny : 3 nx : 1\n", |
| 111 | + "6\n" |
| 112 | + ] |
| 113 | + } |
| 114 | + ], |
| 115 | + "source": [ |
| 116 | + "# actual 2 ) 왕실의 나이트\n", |
| 117 | + "\n", |
| 118 | + "def sol(s):\n", |
| 119 | + " ans = 0\n", |
| 120 | + " \n", |
| 121 | + " y = int(s[1])-1\n", |
| 122 | + " x = ord(s[0])-97\n", |
| 123 | + " \n", |
| 124 | + " moveTypeOneDy = [0, 0]\n", |
| 125 | + " moveTypeOneDx = [2, -2]\n", |
| 126 | + " moveTypeOneFDy = [1, -1]\n", |
| 127 | + " moveTypeOneFDx = [0, 0]\n", |
| 128 | + " \n", |
| 129 | + " moveTypeTwoDy = [2, -2]\n", |
| 130 | + " moveTypeTwoDx = [0, 0]\n", |
| 131 | + " moveTypeTwoFDy = [0, 0]\n", |
| 132 | + " moveTypeTwoFDx = [1, -1]\n", |
| 133 | + " \n", |
| 134 | + " print(str(y) + \" \"+str(x))\n", |
| 135 | + " \n", |
| 136 | + " for i in range(2):\n", |
| 137 | + " nx = x + moveTypeOneDx[i]\n", |
| 138 | + " ny = y + moveTypeOneDy[i]\n", |
| 139 | + " if nx < 0 or ny < 0 or nx >= 8 or ny >= 8:\n", |
| 140 | + " continue\n", |
| 141 | + " for j in range(2):\n", |
| 142 | + " tmpnx = nx\n", |
| 143 | + " tmpny = ny\n", |
| 144 | + " tmpnx = tmpnx + moveTypeOneFDx[j]\n", |
| 145 | + " tmpny = tmpny + moveTypeOneFDy[j]\n", |
| 146 | + " if tmpnx < 0 or tmpny < 0 or tmpnx >= 8 or tmpny >= 8:\n", |
| 147 | + " continue\n", |
| 148 | + " else:\n", |
| 149 | + " ans += 1\n", |
| 150 | + " print(\"ny : \"+str(tmpny) + \" nx : \" + str(tmpnx))\n", |
| 151 | + " \n", |
| 152 | + " \n", |
| 153 | + " for i in range(2):\n", |
| 154 | + " nx = x + moveTypeTwoDx[i]\n", |
| 155 | + " ny = y + moveTypeTwoDy[i]\n", |
| 156 | + " if nx < 0 or ny < 0 or nx >= 8 or ny >= 8:\n", |
| 157 | + " continue\n", |
| 158 | + " for j in range(2):\n", |
| 159 | + " tmpnx = nx\n", |
| 160 | + " tmpny = ny\n", |
| 161 | + " tmpnx = tmpnx + moveTypeTwoFDx[j]\n", |
| 162 | + " tmpny = tmpny + moveTypeTwoFDy[j]\n", |
| 163 | + " if tmpnx < 0 or tmpny < 0 or tmpnx >= 8 or tmpny >= 8:\n", |
| 164 | + " continue\n", |
| 165 | + " else:\n", |
| 166 | + " ans += 1\n", |
| 167 | + " print(\"ny : \"+str(tmpny) + \" nx : \" + str(tmpnx)) \n", |
| 168 | + "\n", |
| 169 | + " \n", |
| 170 | + " \n", |
| 171 | + " return ans\n", |
| 172 | + "\n", |
| 173 | + "s = input()\n", |
| 174 | + "print(sol(s))" |
| 175 | + ] |
| 176 | + }, |
93 | 177 | { |
94 | 178 | "cell_type": "code", |
95 | 179 | "execution_count": null, |
96 | | - "id": "c6dd0155", |
| 180 | + "id": "57a40253", |
97 | 181 | "metadata": {}, |
98 | 182 | "outputs": [], |
99 | | - "source": [] |
| 183 | + "source": [ |
| 184 | + "# actual 3 ) 게임 개발 - 아직 구현 완료되지 않음!\n", |
| 185 | + "\n", |
| 186 | + "def sol(y, x, see, arr):\n", |
| 187 | + " \n", |
| 188 | + " ans = 0\n", |
| 189 | + " \n", |
| 190 | + " move_type = [(-1, 0), (0, 1), (0, -1), (1, 0)]\n", |
| 191 | + " count = 0\n", |
| 192 | + " visited = [[False]*len(arr) for _ in range(len(arr))]\n", |
| 193 | + " while 1:\n", |
| 194 | + " # 1단계\n", |
| 195 | + " if see == 0:\n", |
| 196 | + " see = 3\n", |
| 197 | + " else:\n", |
| 198 | + " see -= 1\n", |
| 199 | + " \n", |
| 200 | + " visited[y][x] = True\n", |
| 201 | + " \n", |
| 202 | + " if count == 4:\n", |
| 203 | + " dy, dx = move_type[(see+2)%4]\n", |
| 204 | + " if arr[y+dy][x+dy] == 1:\n", |
| 205 | + " break\n", |
| 206 | + " count = 0\n", |
| 207 | + " \n", |
| 208 | + " \n", |
| 209 | + " dy, dx = move_type[see]\n", |
| 210 | + " nx = x + dx\n", |
| 211 | + " ny = y + dy\n", |
| 212 | + " \n", |
| 213 | + " if ny < 0 or nx < 0 or nx >= len(arr) or ny >= len(arr):\n", |
| 214 | + " continue\n", |
| 215 | + " if visited[ny][nx] == True or arr[ny][nx] == 1:\n", |
| 216 | + " count += 1\n", |
| 217 | + " continue\n", |
| 218 | + " \n", |
| 219 | + " ans+=1\n", |
| 220 | + " y = ny\n", |
| 221 | + " x = dx\n", |
| 222 | + " \n", |
| 223 | + " \n", |
| 224 | + " return ans\n", |
| 225 | + "\n", |
| 226 | + "n = int(input())\n", |
| 227 | + "y, x, see = map(int, input().split())\n", |
| 228 | + "\n", |
| 229 | + "arr = [list(map(int, input().split())) for _ in range(n)]\n", |
| 230 | + "\n", |
| 231 | + "print(sol(y, x, see, arr))" |
| 232 | + ] |
100 | 233 | }, |
101 | 234 | { |
102 | 235 | "cell_type": "code", |
103 | 236 | "execution_count": null, |
104 | | - "id": "d87fa3ec", |
| 237 | + "id": "e6f16cae", |
105 | 238 | "metadata": {}, |
106 | 239 | "outputs": [], |
107 | 240 | "source": [ |
|
0 commit comments