Skip to content

Commit 784ffcf

Browse files
committed
python
1 parent ac343b4 commit 784ffcf

5 files changed

Lines changed: 174 additions & 0 deletions

File tree

BaekJoon/00.양식.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
3+
# Java
4+
5+
```java
6+
7+
```
8+
9+
# Python
10+
11+
```python
12+
13+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# 왕실의 나이트
2+
3+
```python
4+
import sys
5+
sys.stdin = open("input.txt","r")
6+
7+
board =['0','a','b','c','d','e','f','g','h']
8+
move=[[2,1],[2,-1],[-2,1],[-2,-1],[1,2],[1,-2],[-1,-2],[-1,2]]
9+
n =input()
10+
x=0
11+
for i in range(9):
12+
if n[0] == board[i]:
13+
x=i
14+
y=int(n[1])
15+
cnt = 0
16+
for i in range(8):
17+
if x + move[i][0] >= 1 and x + move[i][0] <=8:
18+
if y + move[i][1] >= 1 and y + move[i][1] <=8:
19+
cnt+=1
20+
else: continue
21+
else: continue
22+
23+
print(cnt)
24+
```

Python/구현_03_게임개발.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# 게임 개발
2+
3+
- 회전과 이동을 동시에하려하니 굉장히 복잡해졌음. 회전을 먼저 시키고 좌표이동을 시키니 훨씬 수훨햇다.
4+
5+
```python
6+
import sys
7+
sys.stdin = open("input.txt","r")
8+
9+
n,m=list(map(int,input().split()))
10+
x,y,p =list(map(int,input().split()))
11+
board =[]
12+
for i in range(n):
13+
board.append(list(map(int, input().split())))
14+
15+
d = [[0] * m for _ in range(n)]
16+
d[x][y] = 1
17+
18+
# 0 육지 1 바다
19+
# 0 1 2 3 북 동 남 서
20+
dx =[0,1,0,-1]
21+
dy =[-1,0,1,0]
22+
turntime=0
23+
cnt=0
24+
25+
while(True):
26+
p-=1
27+
# 왼쪽 방향 바다 회전
28+
if p == -1 : p=3
29+
xx= x+dx[p]
30+
yy= y+dy[p]
31+
if board[xx][yy] == 0 and d[xx][yy] == 0:
32+
turntime=0
33+
d[xx][yy]=1
34+
cnt+=1
35+
x=xx
36+
y=yy
37+
continue
38+
else: # 바다이거나 방문했을때
39+
turntime+=1
40+
if turntime == 4:
41+
nx = x-dx[p]
42+
ny = y-dy[p]
43+
if d[nx][ny] == 0:
44+
d[nx][ny]=1
45+
cnt+=1
46+
x=nx
47+
y=ny
48+
else: break
49+
turntime=0
50+
print(cnt)
51+
52+
```
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# 큰수의 법칙
2+
3+
```python
4+
import sys
5+
sys.stdin = open("input.txt","r")
6+
7+
n,m,k=list(map(int,sys.stdin.readline().split()))
8+
9+
data = list(map(int,input().split()))
10+
data.sort()
11+
12+
res = 0
13+
while(True):
14+
for i in range(k):
15+
if m==0: break
16+
res+=data[-1]
17+
m -= 1
18+
if m == 0:
19+
break
20+
res += data[-2]
21+
m-=1
22+
print(res)
23+
24+
```
25+
26+
- 입력이 100억처럼 커질 경우엔 시간초과가 뜰 수도 있다. 아래와 같이 반복되는 수열에 대해서 파악하고 줄여준다.
27+
28+
```python
29+
import sys
30+
sys.stdin = open("input.txt","r")
31+
32+
n,m,k=list(map(int,sys.stdin.readline().split()))
33+
34+
data = list(map(int,input().split()))
35+
data.sort()
36+
37+
res = 0
38+
first = data[-1]
39+
second= data[-2]
40+
41+
count = int(m / (k+1)) * k
42+
count += m % (k+1)
43+
res += count * first
44+
res += (m-count) *second
45+
print(res)
46+
47+
```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 숫자카드게임
2+
3+
```python
4+
import sys
5+
sys.stdin = open("input.txt","r")
6+
7+
n,m=list(map(int, input().split()))
8+
data=[]
9+
for i in range(n):
10+
data.append(list(map(int, input().split())))
11+
data.sort()
12+
13+
a = 2147000000
14+
temp = -1
15+
for i in range(n):
16+
for j in range(m):
17+
if a > data[i][j]: a = data[i][j]
18+
if (a>temp):
19+
temp = a
20+
print(temp)
21+
22+
```
23+
24+
- 입력 받을때 min값을 기록한다면 더 짧게 가능했다.
25+
26+
```python
27+
import sys
28+
sys.stdin = open("input.txt","r")
29+
30+
n,m=list(map(int, input().split()))
31+
result = 0
32+
for i in range(n):
33+
data=(list(map(int, input().split())))
34+
min_value = min(data)
35+
result = max(min_value, result)
36+
print(result)
37+
38+
```

0 commit comments

Comments
 (0)