One Point Solution

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Wednesday, 7 March 2012

SRM 536: heh

Posted on 05:37 by Unknown
So, once again another SRM. After the bad streak from previous times, I really had to revert it. I am writing this before the end of the challenge phase and it seems I did all right.

Div1 250: The one with the average
You have a list of from 2 to 50 integers. We want to merge them all. After you merge a group of numbers, they are replaced with a value equal to the average of their values. You have to merge until there is only one number left.

From the examples, it looks like it is better to merge larger numbers last. This is actually true. In fact, always merge 2 numbers starting from the smallest ones.

The proof comes from the solution. If we sort an array containing 4 values: {a,b,c,d}, then the result of merging it using the strategy will be: (((a + b)/2 + c) / 2 + d) / 2 ... This translates to : a/8 + b/8 + c/4 + d/2. This means that the largest value will contribute 50% to the result whilst, the smallest two values only 12.5%.


double findMaximum(vector revenues)
{
sort(revenues.begin(), revenues.end());
int n = revenues.size();
double avg = revenues[0];
for (int i=1; i<n; i++) {
avg = (avg + revenues[i]) / 2;
}
return avg;
}



Div1 500: The one that is not (so much) about expected value.

You have many (up to 50) fair dice of 1,2 or up to 1000000000 faces each. Find the most likely outcome of the total sum of the dies. If there are many of them, return the smallest of them.

At first, it really seemed that calculating the expected value will do. At this point I am almost sure that the expected value will indeed be one of the most likely outcomes, but there may be many more sums with a probability equal to that of the expected value. In fact, I am wondering if the variance comes into play . I am almost sure, but maybe there is a case in which the expected value is not even a result, I really need to re-learn statistics.

So, I first coded the expected value thing. I was very doubtful it worked, but I submitted it anyway. Chances are that if I found a solution that didn't use it I would take so long time that the resubmit penalty wouldn't work.

Then I decided to write a bruteforce-dp program to try random sequences until I find a case in which the expected value does not work. I found {2,2,5}, and many others. So I knew my solution was wrong. I tried to spend the rest of the match finding a correct solution. It didn't work.

The bruteforce+dp solution was useful to analyze the problem though. Seeing its output is what makes me think that the expected value is one of the answers (but not always the smallest).

What I usually do once there is no time to fix a solution that I know is wrong is to make a solution that was still wrong but harder to challenge than average (without doing obfuscation). I made a brute-force expected value hybrid, so that it used BF unless the case is too large. I resubmitted but was kind enough to include a comment stating that the solution is wrong.


Challenge
I was able to apply my knowledge of {2,2,5} to gain 50 points. In fact, if I didn't hesitate for a couple of seconds after I opened a second coder's solution, I would have been able to score another successful challenge.

Coders hesitated to challenge my wrong solution for most of the challenge phase. Eventually the top rated coder in my room grabbed the bonus 50 points.

Comments
Perhaps a little too much statistics oriented. But the problems worked.
Email ThisBlogThis!Share to XShare to Facebook
Posted in explanation, srm, topcoder | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • TopCoder SRM 557 - finally
    SRM 557 Explanation for division 1 Easy and match recap. Explanations for div2 easy and div2 medium. It feels like it has been ages since t...
  • SRM 589 Editorial
    I have finished writing the editorial for TopCoder SRM 589: http://apps.topcoder.com/wiki/display/tc/SRM+589 . As you most likely noticed. L...
  • SRM 590 recap and editorial
    Another week another Topcoder match. Not a great day. I had a bad flu and still do. Div1 500: The one with Xor Given a list of cards with nu...
  • SRM 546: relief
    I figured I should post something about this SRM. I've been very busy these weeks because the semester is ending and I tried to win a t-...
  • SRM 526: The killing wait for results
    While I wait for results, here is my perspective on this algorithm contest. It began with issues, it had to be postponed 15 minutes. TC has ...
  • SRM 554 div1 hard: TheBrickTowerHardDivOne
    Link to problem statement We got infinitely many bricks of dimensions 1x1x1 and C different colors. Count the number of towers of size 2x2...
  • SRM 533: Div1 500 MagicBoard explanation
    Finally solved it. It is a nice problem that is worth explaining in a post. You have a grid/board of at most 50x50 cells. Some cells contain...
  • Member SRM 505: Part 1
    So, let me explain a couple of problems from a Topcoder Member SRM that I wrote and never got an editorial. BTW, it was the last member SRM....
  • ListedLinks 2012-02-10
    Saturday Morning Breakfast Cereal comics: Grace Hopper's ghost That Oracle engineer blog post Oracle would really not like anyone to se...
  • Codeforces "Good bye 2013" round
    So it was a special round for coders of both divisions, problems ranged from the super easy problem A to the super difficult problems E,F,G....

Categories

  • acm
  • algorithm
  • answers
  • arenaplugin
  • badday
  • behindthescenes
  • bugs
  • c++
  • censorship
  • codechef
  • codeforces
  • contests
  • crocchamp
  • editorial
  • editorial.srm
  • embarrassing
  • explanation
  • gcj2013
  • gmp
  • goodday
  • google
  • googlecodejam
  • greed
  • groklaw
  • health
  • html
  • httpseverywhere
  • implementation
  • ipsc
  • ispc
  • java
  • kawigiedit
  • kindagoodday
  • lamebook
  • languages
  • lego
  • listedlinks
  • marathon
  • nasa
  • offtopic
  • ouch
  • postmortem
  • postportem
  • practical
  • probably_not_a_good_tip
  • problemsetting
  • programming
  • python
  • quora
  • rant
  • recap
  • slightlygoodday
  • snippet
  • srm
  • stl
  • strategy
  • swerc
  • tco
  • tco12
  • tco13
  • tco2012
  • tco2013
  • ternarysearch
  • topcoder
  • tricks
  • ubuntu
  • uva
  • vjass
  • vkcup
  • wc3
  • zinc

Blog Archive

  • ►  2014 (1)
    • ►  January (1)
  • ►  2013 (141)
    • ►  December (14)
    • ►  November (8)
    • ►  October (13)
    • ►  September (11)
    • ►  August (14)
    • ►  July (15)
    • ►  June (13)
    • ►  May (13)
    • ►  April (12)
    • ►  March (11)
    • ►  February (11)
    • ►  January (6)
  • ▼  2012 (94)
    • ►  December (5)
    • ►  October (6)
    • ►  September (8)
    • ►  August (6)
    • ►  July (3)
    • ►  June (5)
    • ►  May (8)
    • ►  April (10)
    • ▼  March (20)
      • Topcoder Open 2012 round 1A
      • Codeforces round #114. 167C: Wizards and numbers
      • Official TCO 2012 blogger
      • Codeforces round #114 (div1)
      • 5 reasons editorial votes in Topcoder are useless
      • Codeforces VK Cup round 2: (ouch)
      • Codeforces round #113 div2 (unofficial)
      • Writing SRM 538
      • SRM 537: oh my
      • Codeforces round #112
      • Language features: Rants and wishes
      • Google code jam registration - Just note something...
      • Codeforces: VK Cup round 1: Problem C: Abracadabra
      • Codeforces: VK Cup round 1 (update 1)
      • SRM 536: heh
      • SRM 535 editorial: The making of
      • Codeforces round #111 (div2 only)
      • SRM 535 : lame
      • A note about SRM 537 and 540 money prizes
      • The March of Destruction begins!
    • ►  February (16)
    • ►  January (7)
  • ►  2011 (51)
    • ►  December (7)
    • ►  November (12)
    • ►  October (5)
    • ►  September (1)
    • ►  August (3)
    • ►  July (4)
    • ►  June (3)
    • ►  May (7)
    • ►  April (3)
    • ►  March (2)
    • ►  February (1)
    • ►  January (3)
  • ►  2010 (9)
    • ►  December (4)
    • ►  October (1)
    • ►  June (1)
    • ►  May (1)
    • ►  January (2)
  • ►  2009 (1)
    • ►  December (1)
Powered by Blogger.

About Me

Unknown
View my complete profile