LoginSignup
1
0

More than 5 years have passed since last update.

ふたマスの領域の数

Last updated at Posted at 2017-01-18

今回楽すぎませんか?
添字ミスさえなければ10分切れた。

#!/usr/bin/env ruby
#18:15-18:28
#http://nabetani.sakura.ne.jp/hena/ordf01_twicel/
#http://qiita.com/Nabetani/items/8e02ede04315b4eadd6d

H=W=8
def dfs(a,x,y,c)
    a[y][x]=-1
    r=1
    [[-1,0],[0,-1],[1,0],[0,1]].each{|dx,dy|
        if 0<=x+dx&&x+dx<W && 0<=y+dy&&y+dy<H && a[y+dy][x+dx]==c
            r+=dfs(a,x+dx,y+dy,c)
        end
    }
    r
end
while gets
    a=$_.chomp.split('/').map{|e|('%08b'%e.hex).chars.map(&:to_i)}
    r=[0,0]
    8.times{|i|8.times{|j|
        c=a[j][i]
        r[c]+=1 if c>=0&&dfs(a,i,j,c)==2
    }}
    puts r*','
    STDOUT.flush
end
1
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
1
0