LoginSignup
0
0

More than 5 years have passed since last update.

オフラインどう書くE25の問題

Last updated at Posted at 2018-07-08

問題はこちら->https://mtsmfm.github.io/2018/07/07/doukaku-e25.html

90度回転移動の公式を使って解きました。
普通に解くと計算量の爆発があるとかの落とし穴があるのかとも思いましたが、
そういうこともありませんでした。
forループのネストを使いますのでJuliaで書きました。
問題に括弧がありましたので入出力が大変でした。
正規表現を使うのが良いのかもしれませんが、あまり使ったことがありませんし、
特にJuliaのそれはよくわかりません。

str="0  4,7,(0,3)   (0,0),(3,0),(3,6)
1   4,6,(3,3)   (2,5),(0,4),(2,0)
2   1,1,(0,0)   -
3   2,2,(0,0)   -
4   2,3,(0,0)   -
5   2,3,(0,1)   (0,0),(1,0),(1,2)
6   2,3,(1,1)   (1,2),(0,2),(0,0)
7   2,3,(1,2)   -
8   3,4,(1,2)   -
9   4,3,(2,2)   (1,2),(1,1),(3,1)
10  7,7,(2,5)   (0,3),(2,1),(6,5)
11  8,7,(1,1)   (3,0),(4,2),(0,4)
12  9,7,(3,6)   (0,4),(2,1),(8,5)
13  10,7,(6,6)  (3,6),(3,3),(9,3)
14  10,11,(4,2) (8,1),(9,5),(1,7)
15  10,12,(0,3) (3,0),(6,3),(0,9)
16  10,13,(0,0) -
17  10,14,(4,3) (8,2),(9,6),(1,8)
18  15,15,(2,1) (5,0),(6,3),(0,5)
19  16,17,(14,13)   (10,16),(7,12),(15,6)
20  19,7,(18,0) -
21  20,7,(1,4)  (0,1),(3,0),(5,6)
22  25,11,(15,1)    (24,1),(24,10),(6,10)
23  26,12,(12,8)    (4,8),(4,0),(20,0)
24  27,13,(14,2)    (24,2),(24,12),(4,12)
25  28,14,(6,6) -
26  30,30,(25,17)   (20,29),(8,24),(18,0)
27  35,36,(32,3)    (34,8),(29,10),(25,0)
28  150,130,(50,113)    (8,56),(65,14),(149,128)
29  180,120,(120,18)    -
30  200,200,(24,134)    (0,45),(89,21),(137,199)"

function solve(w,h,x,y,ans)
    function cal(w,h,x,y)
        for i in 1:w
            for j in 1:h
                dx=i-x
                dy=j-y
                x1=i-dy
                y1=j+dx
                if x1>0 && y1>0 && x1<w+1 && y1<h+1
                    x2=x1-2*dx
                    y2=y1-2*dy
                    if x2>0 && y2>0 && x2<w+1 && y2<h+1
                       dis=dx^2+dy^2
                       if dis>len
                           len=dis
                           kaz=1
                           pos=(i-1,j-1,x1-1,y1-1,x2-1,y2-1)
                       elseif dis==len
                           kaz=2
                       end
                   end
               end           
           end
        end
    end    
    len=0
    kaz=0
    pos=(0,0,0,0,0,0)
    cal(w,h,x+1,y+1)
    if kaz==1
       s="("*string(pos[1])*","*string(pos[2])*")"*","*"("*string(pos[3])*
       ","*string(pos[4])*")"*","*"("*string(pos[5])*","*string(pos[6])*")"
    else
        s="-"
    end          
    if s==ans 
       print("ok ")
   else
       print("no" )
    end
    println(s) 
end  

str0=split(str,"\n")
for s0 in str0
  s1=split(s0,"\t")
  s2=split(s1[2],",")
 solve(parse(Int,s2[1]),parse(Int,s2[2]),parse(Int,s2[3][2:end]),
        parse(Int,s2[4][1:end-1]),s1[3])
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0