Commit 2985e3b 1 parent 9f8a75c commit 2985e3b Copy full SHA for 2985e3b
File tree 1 file changed +67
-0
lines changed
1 file changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ # 구현, 브루트포스 알고리즘, 시뮬레이션
2
+ # https://www.acmicpc.net/problem/18808
3
+
4
+ import sys
5
+
6
+ input = sys .stdin .readline
7
+ N ,M ,K = map (int , input ().split ())
8
+ stickers = []
9
+ notebook = [[0 ]* M for _ in range (N )]
10
+ answer = 0
11
+
12
+ class Sticker :
13
+ def __init__ (self ):
14
+ R ,C = map (int , input ().split ())
15
+ self .R = R
16
+ self .C = C
17
+ self .S = []
18
+ for _ in range (R ):
19
+ self .S .append (list (map (int , input ().split ())))
20
+
21
+ def paste (self ):
22
+ global N , M
23
+ for _ in range (4 ):
24
+ NN ,MM = N - self .R + 1 , M - self .C + 1
25
+ for n in range (NN ):
26
+ for m in range (MM ):
27
+ if self .add_sticker (n , m ):
28
+ return True
29
+ self .rotate ()
30
+
31
+ return False
32
+
33
+ def add_sticker (self , cr : int , cc : int ):
34
+ global N , M , notebook
35
+ for r in range (self .R ):
36
+ for c in range (self .C ):
37
+ nr , nc = cr + r , cc + c
38
+
39
+ if self .S [r ][c ] == 0 :
40
+ continue
41
+ if 0 > nr or nr >= N :
42
+ return False
43
+ if 0 > nc or nc >= M :
44
+ return False
45
+ if notebook [nr ][nc ] == 1 :
46
+ return False
47
+ self .change (cr , cc )
48
+ return True
49
+
50
+ def rotate (self ):
51
+ self .R , self .C = self .C , self .R
52
+ self .S = list (zip (* self .S [::- 1 ]))
53
+
54
+ def change (self , cr : int , cc : int ):
55
+ global N , M , notebook , answer
56
+ for r in range (self .R ):
57
+ for c in range (self .C ):
58
+ nr , nc = cr + r , cc + c
59
+ if self .S [r ][c ] == 1 :
60
+ notebook [nr ][nc ] = 1
61
+ answer += 1
62
+
63
+ for _ in range (K ):
64
+ sticker = Sticker ()
65
+ sticker .paste ()
66
+
67
+ print (answer )
You can’t perform that action at this time.
0 commit comments