Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
77
Task/Cut-a-rectangle/FreeBASIC/cut-a-rectangle.basic
Normal file
77
Task/Cut-a-rectangle/FreeBASIC/cut-a-rectangle.basic
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
Dim Shared As Ubyte grilla()
|
||||
Dim Shared As Integer ancho, alto, longitud
|
||||
Dim Shared As Integer cnt
|
||||
Dim Shared As Integer sgte(3)
|
||||
Dim Shared As Integer direcc(3, 1) => {{0, -1}, {-1, 0}, {0, 1}, {1, 0}}
|
||||
|
||||
Sub Camino(y As Integer, x As Integer)
|
||||
If y = 0 Or y = alto Or x = 0 Or x = ancho Then
|
||||
cnt += 2
|
||||
Return
|
||||
End If
|
||||
Dim As Integer t = y * (ancho + 1) + x
|
||||
grilla(t) += 1
|
||||
grilla(longitud - t) += 1
|
||||
For i As Integer = 0 To 3
|
||||
If grilla(t + sgte(i)) = 0 Then Camino(y + direcc(i, 0), x + direcc(i, 1))
|
||||
Next
|
||||
grilla(t) -= 1
|
||||
grilla(longitud - t) -= 1
|
||||
End Sub
|
||||
|
||||
Function Solve(hh As Integer, ww As Integer, recur As Boolean) As Integer
|
||||
alto = hh
|
||||
ancho = ww
|
||||
|
||||
If (alto And 1) <> 0 Then Swap alto, ancho
|
||||
|
||||
Select Case True
|
||||
Case (alto And 1) = 1
|
||||
Return 0
|
||||
Case ancho = 1
|
||||
Return 1
|
||||
Case ancho = 2
|
||||
Return alto
|
||||
Case alto = 2
|
||||
Return ancho
|
||||
End Select
|
||||
|
||||
Dim As Integer cy = alto \ 2
|
||||
Dim As Integer cx = ancho \ 2
|
||||
|
||||
Redim grilla((alto + 1) * (ancho + 1))
|
||||
longitud = (alto + 1) * (ancho + 1) - 1
|
||||
sgte(0) = -1
|
||||
sgte(1) = -ancho - 1
|
||||
sgte(2) = 1
|
||||
sgte(3) = ancho + 1
|
||||
|
||||
If recur Then cnt = 0
|
||||
|
||||
For x As Integer = cx + 1 To ancho - 1
|
||||
Dim As Integer t = cy * (ancho + 1) + x
|
||||
grilla(t) = 1
|
||||
grilla(longitud - t) = 1
|
||||
Camino(cy - 1, x)
|
||||
Next
|
||||
cnt += 1
|
||||
|
||||
If alto = ancho Then
|
||||
cnt *= 2
|
||||
Elseif (ancho And 1) = 0 And recur Then
|
||||
Solve(ancho, alto, 0)
|
||||
End If
|
||||
|
||||
Return cnt
|
||||
End Function
|
||||
|
||||
Dim As Integer y, x
|
||||
For y = 1 To 10
|
||||
For x = 1 To y
|
||||
If (x And 1) = 0 Or (y And 1) = 0 Then
|
||||
Print Using "& x &: &"; y; x; Solve(y, x, True)
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue