NUS Home4
Home | Up


Remember your Creator in the days of your youth, fear God and keep his commandments, for this is the whole duty of man - Conclusion of the book of Ecclesiastes.

Last updated on: 07 August 2008 12:04:13 PM

Comment on this volume: None

No

Problem Name * Algorithm

10393-10402: Regionals Warmup Contest 2002 (2002/11/02 4:30-9:30)

10400 Game Show Math 4.5 Backtracking
10401 Injured Queen Problem * Haven't try yet
10402 Triangle Covering * Haven't try yet

10403-10410: November 2002 Monthly Contest (2002/11/09 9:00-14:00)

10403 Escape from Tut's Tomb * Haven't try yet
10404 Bachet's Game 4.5 DP
10405 Longest Common Subsequence 4.5 DP (LCS)
10406 Cutting tabletops * Haven't try yet
10407 Simple division 4.5 Math (GCD)
10408 Farey sequences 4.0 Math (GCD) + Sorting
10409 Die Game 3.0 Ad Hoc
10410 Tree Reconstruction * Haven't try yet

10411-10418: OIBH Online Programming Contest #2 (2002/11/23 6:00-14:00)

10411 Another Game of Tetris * Haven't try yet
10412 Big Big Trees * Haven't try yet
10413 Crazy Savages * Haven't try yet
10414 Denki Blocks * Haven't try yet
10415 Eb Alto Saxophone Player 3.0 Simulation
10416 Folding My T-Shirt * Haven't try yet
10417 Gift Exchanging * Haven't try yet
10418 Hyper Toy Soldiers * Haven't try yet

10419-10428: Warm-up for Beverly Hills (2003/01/11 7:00-13:00)

10419 Sum-up the Primes * Haven't try yet
10420 List of Conquests 2.5 Ad Hoc
10421 Critical Wave * Haven't try yet
10422 Knights in FEN 4.0 Backtracking
10423 Peter Takes a Tramway * Haven't try yet
10424 Love Calculator 4.0 Ad Hoc
10425 Mobile Destroyer * Haven't try yet
10426 Knights' Nightmare * Haven't try yet
10427 Naughty Sleepy Boys * Haven't try yet
10428 The Roots * Haven't try yet

10429-10438: Brightness of Brain Contest (2003/01/18 9:00-15:00)

10429 Mohr's Circle * Haven't try yet
10430 Dear GOD, Pardon Me * Haven't try yet
10431 Normal Distribution * Haven't try yet
10432 Polygon Inside A Circle 2.5 Math (Geometry)
10433 Automorphic Numbers * Haven't try yet
10434 Working With Specific Gravity * Haven't try yet
10435 Compare Directories * Haven't try yet
10436 Cheapest way * Haven't try yet
10437 Playing With Fraction * Haven't try yet
10438 Meta Editor * Haven't try yet

10439-10443: University of Waterloo Local Contest (2003/01/25 18:00-21:00)

10439 Temple of Dune * Haven't try yet
10440 Ferry Loading II 4.5 Greedy
10441 Catenyms * Haven't try yet
10442 Basic * Haven't try yet
10443 Rock, Scissors, Paper 4.0 Ad Hoc

10444-10452: February 2003 Monthly Contest (2003/02/08 8:00-13:00)

10444 Multi-peg Towers of Hanoi * Haven't try yet
10445 Make Polygon * Haven't try yet
10446 The Marriage Interview :-) * Haven't try yet
10447 Sum-up the Primes (II) * Haven't try yet
10448 Unique World * Haven't try yet
10449 Traffic * Haven't try yet
10450 World Cup Noise 3.5 Math (Fibonacci)
10451 Ancient Village Sports 3.0 Math
10452 Marcus, help! 4.0 Graph Traversal

10453-10462: Real Programmers' Contest -2- BUET (2003/02/22 8:00-13:00)

10453 Make Palindrome * Haven't try yet
10454 Trexpression * Haven't try yet
10455 Gray Code * Haven't try yet
10456 Intelligent Cats * Haven't try yet
10457 Magic Car * Haven't try yet
10458 Cricket Ranking * Haven't try yet
10459 The Tree Root * Haven't try yet
10460 Find the Permuted String * Haven't try yet
10461 Difference * Haven't try yet
10462 Is There A Second Way Left? * Haven't try yet

10463-10472: Return of the Aztecs Contest (2003/02/28 9:00-14:00)

10463 Aztec Knights * Haven't try yet
10464 Big Big Real Numbers * Haven't try yet
10465 Homer Simpson 4.5 DP
10466 How Far? 3.5 Math (Trigonometry)
10467 Parse Tree * Haven't try yet
10468 Rigid Circle Packing * Haven't try yet
10469 To Carry or not to Carry 2.0 Math
10470 Shifted Coefficient Number System * Haven't try yet
10471 Can't be too GREEDY * Haven't try yet
10472 Fastest Vs Cheapest * Haven't try yet

10473-10483: World Finals 2003 Warmup (2003/03/10 8:00-13:30)

10473 Simple Base Conversion 4.0 Math (Base Number)
10474 Where is the Marble? 3.5 Sorting + Binary Search
10475 Help the Leaders * Haven't try yet
10476 Spam or Not Spam * Haven't try yet
10477 The Hybrid Knight * Haven't try yet
10478 The Falling Pillars * Haven't try yet
10479 The Hendrie Sequence * Haven't try yet
10480 Sabotage * Haven't try yet
10481 The Gift Wrappers of Hollywood * Haven't try yet
10482 The Candyman Can * Haven't try yet
10483 The Sum Equals the Product * Haven't try yet

10484-10491: UVa Local Qualification (2003/04/26 7:30-12:30)

10484 Divisibility of Factors * Haven't try yet
10485 Painting with CSE * Haven't try yet
10486 Mountain Village * Haven't try yet
10487 Closest Sums 4.0 Simulation
10488 Swimming Gopher * Haven't try yet
10489 Boxes of Chocolates 3.5 Math (Modulo)
10490 Mr. Azad and his Son!!!!! 3.0 Ad Hoc
10491 Cows and Cars 5.0 Math ~ probability formula. Look at Victor's notes

10492-10499: May 2003 Monthly Contest (2003/05/24 11:00-16:40)

10492 Optimal Mastermind Strategy * Haven't try yet
10493 Cats, with or without Hats * Haven't try yet
10494 If We Were a Child Again * Haven't try yet
10495 Conic Distance * Haven't try yet
10496 Collecting Beepers 4.0 Backtracking
10497 Sweet Child Makes Trouble * Haven't try yet
10498 Happiness * Haven't try yet
10499 The Land of Justice 2.5 Math

Total submit-able problems in this volume: 100
Solved problems: 26
Problems in Wrong Answer list from this volume: 5
Unattempted problems: 70
Total hints in this volume: 27


10400 - Game Show Math

I know that from the problem description, the maximum possible combination of the solution is 4^100, which is impossible to calculate. However, I've tried that backtracking with efficient pruning is enough to pass the time limit. Prune when: current value is > 32.000 or < -32.000, or when that value already reached (which means your DFS create cycles...)

10404 - Bachet's Game

Working forwards from n to 0 is not recommended since the search space is extremely too big. Instead, works backward.

If you know that if n==0 and it's Ollie's turn, then Stan obviously win, because Stan has just reached 0 previously.

If n == 1, 3 or 8, the set of legal moves is {1,3,8}, and it's again Stan's turn then Stan will win because his next step will reach state when n == 0 and Ollie's turn.

If n == 2, the set of legal moves is {1,3,8}, and it's Stan's turn, then Stan will lose since he can only move to state when n == 1 and Ollie's turn. Ollie will then use her turn to win the game.

Works this reasoning backwards, up to N. Apply Dynamic Programming by using table to store the intermediate values.

10405 - Longest Common Subsequence

Refer to my programming page, Dynamic Programming section, regarding LCS.

10407 - Simple division

The idea is to find GCD of multiple numbers.

Example from sample input 1:
The value d = 179 can divide the set of integers { 701 1059 1417 2312 },
leaving the same remainder r = 164.

Value d can be calculated by finding the GCD of =
GCD (1059-701, 1417-701, 2312-701) =
GCD (358, 716, 1611) = 179

Since GCD (179) will exactly divides 358, 716, 1611 without any remainders..., then all the original numbers {701 1059 1417 2312} will have remainder of exactly 701 mod 179 = 164. Since the input is in increasing order, the first number in the set will definitely be the smallest and in overall this algorithm will output the biggest d.

10408 - Farey sequences

I know that there is a simpler pattern to solve this problem. However, I've tried that using brute force can pass the time limit. First, generate all possible (i,j) pairs where 1 <= i,j <= n, and gcd(i,j) == 1... (this implies an O(n^2) algorithm), then sort them using quick sort based on their fraction values. After that simply get the k'th index and print it.

10409 - Die Game

Very easy, just simulate, total brute force...

10415 - Eb Alto Saxophone Player

Another simulation, use Boolean array to store pressed/un-pressed state. Number of presses increased if and only if that finger is currently in un-pressed state and now you pressed it. A lot of 'switches' and 'ifs' is required here.

10420 - List of Conquests

This problem is a simple frequency counting. There are many ways to do this, the simplest is to sort the country names (you can ignore all the girls' names...), then count how many time these countries appears.

10422 - Knights in FEN

A simple backtracking will do. The depth limit is 11 moves, if you do it carefully, you should be able to pass the time limit. There must be a faster way... (I see some of you can get Accepted with less than 1 sec), however I don't know the trick yet...

10424 - Love Calculator

Simply the value of 2 given string as given in problem description (digit sum), then compare the ratio... remember that ratio can't be greater than 100%, therefore you must select the smaller between the 2 numbers as numerator and the larger as denominator :)

10432 - Polygon Inside A Circle

First, to avoid stupid precision error, define pi = 2*acos(0.0) !!! Then to calculate the area of the polygon, simply divide them into n smaller triangles. Based on the given radius r, you can get the height and width of this small triangles by trigonometry relation. Finally, calculate the total area of this n triangles :)

10440 - Ferry Loading II

Greedy works. I will not give the proof here, I don't like proofing. However the logical thought are as follows:

For optimality the last ferry must take the last n cars... correct?
Then... the 1st ferry must take the 1st car (car 0) up to car m%n if => m%n != 0
or up to car n if m%n == 0... (otherwise last ferry won't take n cars...)

Now for each ferry trip, last car carried by this ferry trip's time + 2*t is the time this ferry return (for subsequent cars...). If any subsequent car arrives before this, they have to wait. Shift all car arrival timings accordingly. (i.e. if ferry returns at time 50, all cars that arrive < 50 must wait at least until time 50).

Then, time the last car + t (one trip to the other side) is the time last car arrive at destination, the completion time. Done :D

10443 - Rock, Scissors, Paper

This problem is really about manipulating array content (which is a bit hard to debug in my opinion). Prepare two grid arrays (yes, you need 2!!!), then update the new array content based on the content of the old array content + Rock, Scissors, Paper rule.

10450 - World Cup Noise (explanation taken from Message Board)

From the problem description, we must find the number of all binary-strings of length n that don't have consecutive ones.

Let f(n) = number of binary-strings of length n that don't have consecutive ones.

We can split f(n) into two:
1. f0(n) : number of strings that start with '0'.
2. f1(n) : number of strings that start with '1'.

Let's consider f1(n)
If the string starts with '1', clearly the next digit has to be '0', so, the strings are fixed to "10????...". Starting from s[2] until s[n-1], the values are chosen so there is no consecutive ones. That means it is the same as calculating f(n-2).

f0(n) starts with '0', the next digit can be either '0' or '1' ... The strings are only fixed to pattern "0????..." and the rest should be chosen in such a way so that no consecutive ones are found. It's the same as recursively calculating f(n-1).

We can see that f(n) = f(n-2) + f(n-1) ... which is Fibonacci sequence.

10451 - Ancient Village Sports

This problem is basically a twisted problem 10432 (see above), if you know the formula to solve 10432, then you'll be able to derive similar (but a bit different) formula to solve this.

10452 - Marcus, help!

The issue of whether the God "IEHOVA" exist or not is another issue. In this problem, use DFS to correctly choose the step to reach the destination. Note that this path is definitely exist (see problem description), so your output should always be 7 steps...

10465 - Homer Simpson

I know the problem description seems unclear. However after some contemplation, I realize that this is just a standard DP problem. Create two arrays, maxBurger[1..T] and beer[1..T], then use the following derivation:

Base case, from time t, from 1 to min(m,n) - 1:
  The number of burger that Homer can take is 0, i.e. maxBurger[t] = 0;
  Homer must drink t litres of beer, i.e. beer[t] = t;

General case, from time min(m,n) to T:
  The number of burger that Homer can take is max(maxBurger[t-n],maxBurger[t-m]) + 1
  But, in this problem, we must consider another criteria, take those burger if the
    number of beer needed is smaller. I'll leave this to you to figure out how to handle this :)

10466 - How Far?

A simple trigonometry problem. I'm sure you already know this formula from high school, that in right triangle: length_of_x = cos(degree) * radius and length_of_y = sin(degree) * radius.

This problem just ask you to calculate them...

10469 - To Carry or not to Carry

Use unsigned long, and then simply XoR them :)

10473 - Simple Base Conversion

Base number conversion is popular topic, refer to math books if you don't know how to do this.

10474 - Where is the Marble?

Read the input, sort them, then search the query element using binary search. Don't forget to find the first element that is matched with the query instead of the one that returned by binary search.

10487 - Closest Sums

Read the input, sort them, and then do O(n^2) pairing..., if the sum has the closest match to the query, output it. Purely brute force :p

10489 - Boxes of Chocolates (By: Niaz)

A very simple problem. You will be given a sequence of box descriptions. Just multiply the elements with each other and finally MOD by number of friends and the remainder will be the result. But there is a big problem. If you do it this way, your value will overflow. To avoid this, we will take the help of modular operation. According to modular operation we can do MOD just after each multiplication.

Example:

input
1
5 1
3 2 3 4
output
4

Calculation for this input:
R = 1
R = (R * 2) % 5  
R = (R * 3) % 5
R = (R * 4) % 5

Now R will holds 4. For large value this method will help you to avoid overflow. NOTE: In case of more than one line, take the sum for each line and finally MOD it with number of friends.

10490 - Mr. Azad and his Son!!!!!

You can count it yourself, after that pre-calculate the answers.

First 10 primes <= 31 are {2,3,5,7,11,13,17,19,23,29,31};
n == 11 || n == 23 || n == 29 are prime but not perfect, exclude them.
For the rest, just calculate 2^(k-1) * (2^k - 1)

10491 - Cows and Cars (Derivation by: Victor Loh)

The solution for this problem is:
(1.0*(ncows*ncars+ncars*(ncars-1))/(ncows+ncars-nshow-1))/(ncows+ncars));

Derivation:
P(winning a car) = P(car 1st & change to another car) + P(cow 1st & change to car)
P(car 1st & change to another car) = ncar/(ncar + ncow) * (ncar-1)/(ncar + ncow - nshow - 1)
P(cow 1st & change to car) = ncow/(ncar + ncow) * ncar/(ncar + ncow - nshow - 1)

Simplifying and we get your formula, and further simplification gives you:

ncar * (ncow + ncar - 1)
-----------------------------------------
(ncow+ncar) * (ncow + ncar - nshow - 1)

10496 - Collecting Beepers

A simple backtracking problem. Simply enumerate all possible paths that Karel may take. Prune the search tree as necessary (when current length is already exceed best known shortest path length).

10499 - The Land of Justice

Okay, just follow this derivation:

1. Do you know that 4 * area of circle = area of sphere (their diameter must be the same)
2. Every cut that you do, will create 2 * 1/2 * area of circle + 1/N * area of sphere
3. If you have N cuts, you will have: N * (2 * 1/2 * area of circle + 1/ N * area of sphere)
4. The formula can be simplified to: N * area of circle + area of sphere
5. Substitute area of circle == 1/4 area of sphere
6. Our formula is now: N/4 area of sphere + area of sphere
7. We want to know our profit: which is: area of all cuts / area of original sphere
8. (1 + N/4) area of sphere / area of sphere == 1 + N/4, our profit is N/4.
9. Since we want it to be displayed in percentage, profit: N/4 * 100 ==> N * 25.
10. Finished... BUT... don't forget the special case: if N == 1, you don't have any profit!!!


This document, volC4.html, has been accessed 11602 times since 16-Sep-03 11:34:39 SGT. This is the 1st time it has been accessed today.

A total of 5776 different hosts have accessed this document in the last 1819 days; your host, 38.103.63.60, has accessed it 1 times.

If you're interested, complete statistics for this document are also available, including breakdowns by top-level domain, host name, and date.