Created
December 3, 2011 17:58
-
-
Save methane/1427702 to your computer and use it in GitHub Desktop.
Skeleton code of codevs.jp
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
#!/usr/bin/python | |
# coding: utf-8 | |
import sys | |
import fileinput | |
def read_ints(f): | |
return map(int, f.readline().strip().split()) | |
def read_line(f): | |
return f.readline().strip() | |
def read_map(fi): | |
w, h = read_ints(fi) | |
_map = [] | |
for y in xrange(h): | |
L = read_line(fi) | |
assert len(L) == w, "Bad width" | |
_map.append(L) | |
return (w, h, _map) | |
def read_level(fi): | |
life, money, tower_count, enemy_count = read_ints(fi) | |
towers = [] | |
for t in xrange(tower_count): | |
# tuple of (X, Y, A, C) | |
tower = tuple(read_ints(fi)) | |
assert len(tower) == 4 | |
towers.append(tower) | |
enemies = [] | |
for e in xrange(enemy_count): | |
# tuple of (X, Y, T, L, S) | |
enemy = tuple(read_ints(fi)) | |
assert len(enemy) == 5 | |
enemies.append(enemy) | |
end = read_line(fi) | |
assert end == "END" | |
return (life, money, towers, enemies) | |
def main(): | |
fi = fileinput.input() | |
n_map, = read_ints(fi) | |
for i in xrange(n_map): | |
_map = read_map(fi) | |
levels, = read_ints(fi) | |
end = read_line(fi) | |
assert end == "END" | |
for l in xrange(levels): | |
level_data = read_level(fi) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment