We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Loading...
  • Practice
  • Compete
  • Jobs
  • Leaderboard
  • Hiring developers?
  1. Practice
  2. Algorithms
  3. Implementation
  4. Chocolate Feast
  5. Discussions

Chocolate Feast

  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial
  • Topics

    You are viewing a single comment's thread. Return to all comments →

  • cferguson 4 years ago+ 1 comment

    That's basically what I did, except in Python.

    choc, wrappers = [int(n/c), int(n/c)]
    while (wrappers >= m):
        choc+= 1
        wrappers -= m
        wrappers += 1
    print(choc)
    
    0|
    ParentPermalink
    • SebastianNielsen 2 years ago+ 1 comment

      A better version:

      choc = wrappers = n // c
      
      while (wrappers >= m):
          choc+= 1
          wrappers -= m - 1 
      print(choc)
      
      4|
      ParentPermalink
      • mike_buttery 6 months ago+ 0 comments

        Similar here without iterating every bar/wrapper swap

        bars = wrappers = n // c
         
        while wrappers >= m:
            bars += wrappers // m
            wrappers -= wrappers // m * (m - 1)
        
        return bars
        
        0|
        ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature