Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from heapq import heapify, heappop, heappush
- def area(size):
- return size * size * 3.141592
- def largestPiece(cakeDiameters, slicesToFind):
- cakes = [(-area(x), 1, area(x)) for x in cakeDiameters]
- heapify(cakes)
- biggestSize = 99999999 #MaxInt
- for number in range(slicesToFind):
- current, currentSlicesInCake, originalSize = heappop(cakes)
- biggestSize = -current
- newSlicesInCake = currentSlicesInCake + 1
- newSize = (originalSize / newSlicesInCake) * -1
- nextEntry = (newSize, newSlicesInCake, originalSize)
- heappush(cakes, nextEntry)
- return biggestSize
- slicesToGet = 4
- print(largestPiece([1, 1, 1, 2, 2, 3], slicesToGet))
- """Given a list of cakes by their radii, and a number of slices to be made,
- get the largest slice size that can made from these cakes assuming you want an
- equal slice size, and a slice can't be composed from more than one cake"""
Advertisement
Add Comment
Please, Sign In to add comment