Skip to content

Instantly share code, notes, and snippets.

@igorsobreira
Created March 23, 2011 04:06
Show Gist options
  • Save igorsobreira/882597 to your computer and use it in GitHub Desktop.
Save igorsobreira/882597 to your computer and use it in GitHub Desktop.
#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