Skip to content

Instantly share code, notes, and snippets.

@dragon0
Created September 12, 2015 06:33
Show Gist options
  • Save dragon0/8ea094c50e82b2f5d60d to your computer and use it in GitHub Desktop.
Save dragon0/8ea094c50e82b2f5d60d to your computer and use it in GitHub Desktop.
Fifty Coats Of Gray ACM Problem
#!/usr/bin/env python3
from math import ceil
def base_area(n, width, length, height):
return n * ( 2 * width * height + 2 * length * height + length * width)
def run_case(in_it):
n, width, length, height, area, m = next(in_it).split()
n = int(n)
width = int(width)
length = int(length)
height = int(height)
area = int(area)
m = int(m)
if n == width == length == height == area == m == 0:
return
r_area = base_area(n, width, length, height)
for _ in range(m):
w, h = next(in_it).split()
w = int(w)
h = int(h)
r_area -= n * w * h
return r_area / area
def run_all(in_it):
while True:
result = run_case(in_it)
if result is not None:
print(ceil(result))
else:
break
if __name__ == '__main__':
#import sys
#run_all(sys.stdin)
sample = '''
50 8 20 8 350 2
6 3
3 3
50 8 20 8 300 3
6 3
5 3
3 3
0 0 0 0 0 0
'''
sample = sample.strip().split('\n')
run_all(iter(sample))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment