Last active
November 5, 2018 01:49
-
-
Save Crilou/a14705a97867b9100d7ea2c4e68ff253 to your computer and use it in GitHub Desktop.
BATMAN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
//import "math" | |
//import "os" | |
type AB struct { | |
A int | |
B int | |
} | |
func main() { | |
var W, H int | |
fmt.Scan(&W, &H) | |
var N int | |
fmt.Scan(&N) | |
var X0, Y0 int | |
fmt.Scan(&X0, &Y0) | |
var goX, goY int = X0, Y0 | |
var ( | |
inthor = AB{0,W-1} | |
intver = AB{0,H-1} | |
lastpos = AB{X0,Y0} | |
pos = AB{X0,Y0} | |
) | |
var dirhor, dirver string | |
for { | |
var bombDir string | |
fmt.Scan(&bombDir) | |
pos.A=goX | |
pos.B=goY | |
if inthor.A!=inthor.B { | |
switch bombDir { | |
case "UNKNOWN": | |
if X0 < W/2 { | |
dirhor = "TOTHERIGHT" | |
goX = inthor.B | |
if goX==pos.A {goX++} | |
} else { | |
dirhor = "TOTHELEFT" | |
goX = inthor.A | |
if goX==pos.A {goX--} | |
} | |
case "WARMER": | |
if dirhor=="TOTHERIGHT" { | |
inthor.A=inthor.B-(goX-lastpos.A-1)/2 | |
goX = inthor.A | |
if goX==pos.A {goX++} | |
dirhor="TOTHELEFT" | |
} else { | |
inthor.B=inthor.A+(lastpos.A-goX-1)/2 | |
goX = inthor.B | |
dirhor="TOTHERIGHT" | |
} | |
case "COLDER": | |
if dirhor=="TOTHERIGHT" { | |
inthor.B=inthor.A+(goX-lastpos.A-1)/2 | |
goX = inthor.A | |
if goX==pos.A {goX--} | |
dirhor="TOTHELEFT" | |
} else { | |
inthor.A=inthor.B-(lastpos.A-goX-1)/2 | |
goX = inthor.B | |
if goX==pos.A {goX++} | |
dirhor="TOTHERIGHT" | |
} | |
case "SAME": | |
inthor.A=(lastpos.A+goX)/2 | |
inthor.B=inthor.A | |
goX=inthor.A | |
if Y0 < H/2 { | |
dirver = "TOTHEBOTTOM" | |
goY = intver.B | |
if goY==pos.B {goY++} | |
} else { | |
dirver = "TOTHETOP" | |
goY = intver.A | |
if goY==pos.B {goY--} | |
} | |
} | |
} else { | |
if dirver=="" {bombDir="UNKNOWN"} | |
switch bombDir { | |
case "UNKNOWN": | |
if Y0 < H/2 { | |
dirver = "TOTHEBOTTOM" | |
goY = intver.B | |
if goY==pos.B {goY++} | |
} else { | |
dirver = "TOTHETOP" | |
goY = intver.A | |
if goY==pos.B {goY--} | |
} | |
case "WARMER": | |
if dirver=="TOTHEBOTTOM" { | |
intver.A=intver.B-(goY-lastpos.B-1)/2 | |
goY = intver.A | |
if goY==pos.B {goY++} | |
dirver="TOTHETOP" | |
} else { | |
intver.B=intver.A+(lastpos.B-goY-1)/2 | |
goY = intver.B | |
if goY==pos.B {goY--} | |
dirver="TOTHEBOTTOM" | |
} | |
case "COLDER": | |
if dirver=="TOTHEBOTTOM" { | |
intver.B=intver.A+(goY-lastpos.B-1)/2 | |
goY = intver.A | |
if goY==pos.B {goY--} | |
dirver="TOTHETOP" | |
} else { | |
intver.A=intver.B-(lastpos.B-goY-1)/2 | |
goY = intver.B | |
if goY==pos.B {goY++} | |
dirver="TOTHEBOTTOM" | |
} | |
case "SAME": | |
intver.A=(lastpos.B+goY)/2 | |
intver.B=intver.A | |
goY=intver.A | |
} | |
} | |
lastpos.A=pos.A | |
lastpos.B=pos.B | |
// fmt.Fprintln(os.Stderr, "Debug messages...") | |
fmt.Printf("%v %v\n",goX,goY)// Write action to stdout | |
} | |
} | |
package main | |
import "fmt" | |
//import "math" | |
//import "os" | |
func main() { | |
var W, H int | |
fmt.Scan(&W, &H) | |
var N int | |
fmt.Scan(&N) | |
var X0, Y0 int | |
fmt.Scan(&X0, &Y0) | |
var goX, goY int = X0, Y0 | |
var top,bot,left,right int = 0, H-1, 0, W-1 | |
var prdubeurre,step bool=false, true | |
var tour string | |
for { | |
var bombDir string | |
fmt.Scan(&bombDir) | |
if prdubeurre==true { | |
prdubeurre=false | |
tour="TL" | |
} else { | |
switch bombDir { | |
case "UNKNOWN": | |
goX=0 | |
goY=0 | |
prdubeurre=true | |
case "WARMER": | |
switch tour { | |
case "TL": | |
if step {bot=top+(bot-top-1)/2} | |
case "TR": | |
if step {left=right-(right-left-1)/2} | |
case "BR": | |
if step {top=bot-(bot-top-1)/2} | |
case "BL": | |
if step {right=left+(right-left-1)/2} | |
} | |
case "COLDER": | |
switch tour { | |
case "TL": | |
if step {top=bot-(bot-top-1)/2} | |
case "TR": | |
if step {right=left+(right-left-1)/2} | |
case "BR": | |
if step {bot=top+(bot-top-1)/2} | |
case "BL": | |
if step {left=right-(right-left-1)/2} | |
} | |
case "SAME": | |
switch tour { | |
case "TL": | |
top=top+(bot-top)/2 | |
bot=top | |
case "TR": | |
left=left+(right-left)/2 | |
right=left | |
case "BR": | |
top=top+(bot-top)/2 | |
bot=top | |
case "BL": | |
left=left+(right-left)/2 | |
right=left | |
case "": | |
} | |
} | |
} | |
switch tour { | |
case "TL": | |
if left!=right { | |
tour="TR" | |
goX=right | |
goY=top | |
} else { | |
step=false | |
tour="BR" | |
goX=right | |
goY=bot | |
} | |
case "TR": | |
if top!=bot { | |
tour="BR" | |
goX=right | |
goY=bot | |
} else { | |
step=false | |
tour="BL" | |
goX=left | |
goY=bot | |
} | |
case "BR": | |
if left!=right { | |
tour="BL" | |
goX=left | |
goY=bot | |
} else { | |
step=false | |
tour="TL" | |
goX=left | |
goY=top | |
} | |
case "BL": | |
if top!=bot { | |
tour="TL" | |
goX=left | |
goY=top | |
} else { | |
step=false | |
tour="TR" | |
goX=right | |
goY=top | |
} | |
} | |
// fmt.Fprintln(os.Stderr, "Debug messages...") | |
fmt.Printf("%v %v\n", goX,goY)// Write action to stdout | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment