-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomb,perm,bfs,sort간단 예.py
153 lines (140 loc) · 3.02 KB
/
comb,perm,bfs,sort간단 예.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from collections import deque
import random
def get_random_numbers():
numbers = random.sample(range(1, 51), 3)
return numbers
lst=[]
for i in range(5):
random.seed(i)
lst.append(get_random_numbers())
print(lst)
print("디폴트 정렬(1순위로 첫항 2순위로 둘째항 3순위로 셋째항을 기준으로 크기 정렬)")
print(sorted(lst))
print("1순위 첫째항 크기 2순위 둘째항 크기역순 3순위 셋째항 역순 정렬)")
sorted_lst=sorted(lst,key=lambda x:(x[0],-x[1],-x[2]))
print(sorted_lst)
print("1순위 둘째항 크기 3순위 첫째항 역순 정렬)")
sorted_lst=sorted(lst,key=lambda x:(x[1],-x[0]))
print(sorted_lst)
#
# #배열을 정렬할때 1순위는 두번째요소 크기순, 2순위는 세번째요소(크기역순) 으로 정렬하기 연습
#
# def deepcopy(arr):
# temp=[]
# for i in arr:
# temp.append(i)
# return temp
#
# def BFS(board,start,goal):
# global d,visit,ans
# d.append(start)
# dr=[1,0,-1,0]
# dc=[0,1,0,-1]
#
# visit[start[0]][start[1]] = 1
# while d:
# r,c=d.popleft()
# for i in range(4):
# nr=r+dr[i]
# nc=c+dc[i]
# if 0<=nr<4 and 0<=nc<6 and not visit[nr][nc] and board[nr][nc]==1:
# d.append([nr,nc])
# visit[nr][nc]=1
# foot_print[nr][nc]=[r,c]
# if [nr,nc]==goal:
# print(d)
# return
#
#
# d=deque()
# ans=[]
# board=[[1,0,1,1,1,1],
# [1,0,1,0,1,0],
# [1,0,1,0,1,1],
# [1,1,1,0,1,1]]
#
# foot_print=[[[9,9] for i in range(len(board[0]))] for i in range(len(board))]
# visit=[[0 for i in range(len(board[0]))] for i in range(len(board))]
# start = [0,0]
# end = [3,5]
#
# BFS(board,start,end)
#
# for i in visit:
# print(i)
#
# print(d)
# for i in foot_print:
# print(i)
#
#
# r,c=end
#
# ans=[end]
# while True:
# ans.append(foot_print[r][c])
# r,c=foot_print[r][c]
# if [r,c]==start:
# break
# print("foot print")
# print(list(reversed(ans)))
#
#
#
#
# def deepcopy(arr):
# t=[]
# for i in arr:
# t.append(i)
# return t
#
#
# def permute(goal, cnt, lst, stack=[]):
# global perm, visit
#
# if goal == cnt:
# perm.append(deepcopy(stack))
# return
#
# for i in range(len(lst)):
# if not visit[i]:
# visit[i] = 1
# stack.append(lst[i])
# permute(goal, cnt + 1, lst, stack)
# stack.pop()
#
# visit[i] = 0
#
#
# def combi(goal, cnt, lst, idx,stack=[]):
# global comb, visit
#
# if goal == cnt:
# comb.append(deepcopy(stack))
# return
#
# for i in range(idx,len(lst)):
# if not visit[i]:
# visit[i] = 1
# stack.append(lst[i])
# combi(goal, cnt + 1, lst,i, stack)
# stack.pop()
#
# visit[i] = 0
#
#
#
#
#
#
#
# perm=[]
# comb=[]
# lst=[1,2,3,4,5]
# visit=[0 for i in range(len(lst))]
#
# permute(2,0,lst)
# combi(2,0,lst,0)
#
# print(perm)
# print(comb)