Created
March 23, 2011 04:06
-
-
Save igorsobreira/882597 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
#INPUT = 'example.txt' | |
INPUT = "A-large-practice.in" | |
def main(): | |
file_obj = open(INPUT) | |
cases = int(file_obj.readline()) | |
for i in range(cases): | |
n = int(file_obj.readline()) | |
lines = read_next_n_lines(file_obj, n) | |
solve_case(i+1, lines) | |
file_obj.close() | |
def read_next_n_lines(file_obj, n): | |
lines = [] | |
while n > 0: | |
lines.append(map(int, file_obj.readline().rstrip('\n').split())) | |
n -= 1 | |
return lines | |
def solve_case(case_id, lines): | |
inters = 0 | |
for (i, (a,b)) in enumerate(lines): | |
for ai,bi in lines[0:i]: | |
if (a > ai and bi > b) or (a < ai and b > bi): | |
inters += 1 | |
print "Case #%d: %d" % (case_id, inters) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment