Created
December 10, 2015 19:36
-
-
Save yamaguchi1024/6ba76f2830626fb4856e to your computer and use it in GitHub Desktop.
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
$n = gets.chomp.to_i | |
$money = gets.chomp.to_i | |
$board = Array.new($n) | |
$n.times.with_index {|i| | |
$board[i] = gets.chomp.split('') | |
} | |
#warn $board | |
$bases=Array.new | |
$n.times do |i| | |
$n.times do |j| | |
if ($board[i][j]!='#' && $board[i][j]!='.') then | |
$bases << [i,j] | |
end | |
end | |
end | |
#warn $bases | |
creepHealth = gets.chomp.to_i | |
creepmoney = gets.chomp.to_i | |
Tower = Struct.new(:range, :damage, :cost) # 武器となるTowerの情報を保存するデータ構造 | |
$m = gets.chomp.to_i # Towerの種類 | |
$towers=Array.new | |
$m.times{ | |
range, damage, cost = gets.split.map(&:to_i) | |
$towers<<Tower.new(range,damage,cost); | |
} | |
#warn $towers | |
tmp=-100 | |
$goodtower=Array.new | |
$m.times do |i| | |
if ($towers[i].range+$towers[i].damage)/$towers[i].cost > tmp | |
$goodtower=[i,$towers[i].range,$towers[i].damage,$towers[i].cost] | |
tmp=($towers[i].range*3+$towers[i].damage)/$towers[i].cost | |
end | |
end | |
#warn $goodtower | |
$built = Array.new($n).map{Array.new($n,false)} | |
Creep = Struct.new(:id, :health, :column, :row) # 敵の情報を保存するデータ構造 | |
def good_tower_ichi | |
$good_t_ichi=Array.new | |
# $n.times do |i| | |
# warn i | |
# if ($board[0][i]=='.' && $board[0][i-1]=='#') | |
# $good_t_ichi << [0,i-1] | |
# elsif ($board[i][0]=='.' && $board[i+1][0]=='#') | |
# $good_t_ichi << [i+1,0] | |
# elsif ($board[$n][i]=='.' && $board[$n][i+1]=='#') | |
# $good_t_ichi << [$n,i+1] | |
# elsif ($board[i][$n]=='.' && $boatd[i+1][$n]=='#') | |
# $good_t_ichi << [i+1,$n] | |
# end | |
# end | |
$n.times do |i| | |
$n.times do |j| | |
if $good_t_ichi.size==0 | |
if $board[i][j]=='#' && ($board[i-1][j]=='.' || $board[i][j-1]=='.') && !$built[i][j] | |
#warn $money | |
#warn $goodtower[3] | |
$good_t_ichi<<[i,j] | |
$built[i][j]=true | |
$money=$money-$goodtower[3] | |
#warn "nuinui" | |
end | |
else | |
if $money>$goodtower[3] && $board[i][j]=='#' && ($board[i-1][j]=='.' || $board[i][j-1]=='.') && !$built[i][j] | |
cookies=true | |
($good_t_ichi.size).times do |p| | |
if distance(i,j,$good_t_ichi[p][0],$good_t_ichi[p][1])<$goodtower[1] | |
cookies=false | |
end | |
end | |
if cookies==true | |
$good_t_ichi<<[i,j] | |
$built[i][j]=true | |
$money=$money-$goodtower[3] | |
end | |
end | |
end | |
end | |
end | |
end | |
def puttower(k,b) | |
ki=false | |
7.times do | |
# column = rand(n) | |
# row = rand(n) | |
# kind = rand(m) | |
row=$bases[b][0]-rand(-3..3) | |
column=$bases[b][1]-rand(-3..3) | |
cost=$goodtower[3] | |
kind=$goodtower[0] | |
#if ((distance($bases[b][0],$bases[b][1],row,column)+1<$goodtower[1]) && !$built[row][column] && (cost < $money) && ($board[row][column] == '#')) | |
if (!$built[row][column] && (cost < $money) && ($board[row][column] == '#')) | |
$ret << [column,row,kind] | |
$built[row][column]=true | |
$money=$money-cost | |
ki=true | |
break | |
#warn "no" | |
end | |
if ki==true | |
break | |
end | |
#warn "popo" | |
end | |
end | |
def init | |
good_tower_ichi | |
($good_t_ichi.size).times do |i| | |
$ret << [$good_t_ichi[i][1],$good_t_ichi[i][0],$goodtower[0]] | |
end | |
# warn $ret | |
end | |
def distance(x,y,z,w) | |
Math.sqrt((x-z)**2+(y-w)**2) | |
end | |
#init(n,m) | |
(2000).times do |pyon| | |
# warn "1" | |
$money = gets.chomp.to_i | |
# warn "2" | |
creepNum = gets.chomp.to_i | |
creeps = Array.new | |
creepNum.times{ | |
id, health, column, row = gets.split.map(&:to_i) | |
creeps << Creep.new(id, health, column, row) | |
} | |
# warn "3" | |
b = gets.chomp.to_i # Base の数 | |
b.times{ | |
baseHealth = gets.chomp.to_i | |
} | |
$ret = Array.new | |
# warn "4" | |
if pyon==0 | |
init | |
else | |
creepNum.times do |i| | |
($bases.length).times do |j| | |
if ((creeps[i].row-$bases[j][0]).abs < 4) && ((creeps[i].column-$bases[j][1]).abs < 4) then | |
puttower(i,j) | |
end | |
end | |
end | |
end | |
# warn $ret.length | |
# warn $ret | |
puts $ret.length | |
$ret.length.times.with_index{|i| | |
puts $ret[i].join(' ') | |
} | |
# warn "5" | |
STDOUT.flush | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment