fork download
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6. var n, r, c int
  7. fmt.Scanf("%d", &n)
  8.  
  9. code := make([]string, n)
  10. for i := 0; i < n; i++ {
  11. var s string
  12. fmt.Scanf("%s", &s)
  13. code[i] = s[1:] + s[:1]
  14. }
  15.  
  16. s := []int{2, 4, 8, 16, 32, 64, 128}
  17. fmt.Scanf("%d %d", &r, &c)
  18.  
  19. d := r
  20. if r < c {
  21. d = c
  22. }
  23. for i := 0; i < 7; i++ {
  24. if d <= s[i] {
  25. d = s[i]
  26. break
  27. }
  28. }
  29.  
  30. grid := make([][]int, d)
  31. for i := 0; i < d; i++ {
  32. grid[i] = make([]int, d)
  33. for j := 0; j < d; j++ {
  34. grid[i][j] = 0
  35. }
  36. }
  37.  
  38. quadtree(grid, 0, 0, d, code)
  39.  
  40. // TODO: Change to r and c
  41. for i := 0; i < d; i++ {
  42. for j := 0; j < d; j++ {
  43. if j > 0 {
  44. fmt.Print(" ")
  45. }
  46. fmt.Print(grid[i][j])
  47. }
  48. fmt.Println()
  49. }
  50. }
  51.  
  52. func quadtree(grid [][]int, r, c, d int, code []string) {
  53. if len(code) == 1 && len(code[0]) == 1 {
  54. if code[0][0] == '1' {
  55. for i := r; i < r+d; i++ {
  56. for j := c; j < c+d; j++ {
  57. grid[i][j] = 1
  58. }
  59. }
  60. }
  61. return
  62. }
  63.  
  64. _code := make([][]string, 4)
  65. for i := 0; i < 4; i++ {
  66. _code[i] = []string{}
  67. }
  68. for i := 0; i < len(code); i++ {
  69. q := []rune(code[i])[0]-'0'
  70. _code[q] = append(_code[q], code[i][1:])
  71. }
  72.  
  73. _d := d>>1
  74. for i := 0; i < 4; i++ {
  75. if len(_code[i]) > 0 {
  76. _r := r + (i>>1)*_d
  77. _c := c + (i&1)*_d
  78. quadtree(grid, _r, _c, _d, _code[i])
  79. }
  80. }
  81. }
Success #stdin #stdout 0s 5284KB
stdin
6
10
110
112
120
121
130
3 3
stdout
1 1 1 0
1 1 1 0
1 1 1 0
0 0 0 0