NUS Home10
Home Up


Last updated on: 04 May 2009 01:04:38 PM

Comment on this volume: The hints for this volume are contributed by my CS3233 students:
11000-11049: Gaurav Chandrashekar, Faculty of Engineering, 2008/09 (GC)
11050-11099: Guan Yizheng (GY)

No

Problem Name

*

Algorithm

Solved by

Assigned to Gaurav Chandrashekar

11000 Bee 4.5 Math GC
11001 Necklace * Ad Hoc GC
11002 Towards Zero * DP GC
11003 Boxes * DP GC
11004 ? * * *
11005 Cheapest Base * Math GC
11006 ? * * *
11007 ? * * *
11008 Antimatter Ray Clearcutting * DP GC, BR
11009 ? * * *
11010 ? * * *
11011 ? * * *
11012 Cosmic Cabbages * DP GC
11013 ? * * *
11014 ? * * *
11015 05-32 Rendezvous 4.0 Graph, All Pairs Shortest Paths, Floyd GC
11016 ? * * *
11017 ? * * *
11018 ? * * *
11019 Matrix Matcher * Ad Hoc GC
11020 Efficient Solutions * Ad Hoc GC
11021 ? * * *
11022 String Factoring * DP GC
11023 ? * * *
11024 ? * * *
11025 ? * * *
11026 A Grouping Problem * DP GC
11027 ? * * *
11028 Sum of Product * Math GC
11029 Leading and Trailing * Math GC
11030 ? * * *
11031 Looking for a Subset * DP GC
11032 Function Overloading * DP GC
11033 ? * * *
11034 Ferry Loading IV * Simulation GC
11035 ? * * *
11036 ? * * *
11037 ? * * *
11038 How Many 0's? * Ad Hoc GC
11039 Building Designing * Greedy GC
11040 Add bricks in the wall * DP GC
11041 ? * * *
11042 Complex, difficult and complicated * Ad Hoc GC
11043 ? * * *
11044 Searching for Nessy 1.0 Math GC
11045 My T-Shirt suits me 5.5 Graph, Bipartite Matching, Max Flow SH, GC
11046 ? * * *
11047 The Scrooge Co Problem 4.0 Graph, All Pairs Shortest Paths, Floyd GC
11048 ? * * *
11049 Basic Wall Maze ? ? GC

Assigned to Guan Yizheng

11050 Construct the wall maze * *

*

11051 ? * *

*

11052 ? * *

*

11053 ? * *

*

11054 Wine trading in Gergovia * Greedy

GY

11055 Homogeneous squares * Math

GY

11056 Formula 1 * Sorting

GY

11057 Exact Sum * Ad Hoc

SH, GC

11058 Encoding * String Processing

GY

11059 Maximum Product * Complete Search

SH, GC

11060 ? * *

*

11061 ? * *

*

11062 Andy's Second Dictionary * String Processing

GY

11063 B2-Sequence * Complete Search

GY

11064 Number Theory * Math

GY

11065 ? * *

*

11066 ? * *

*

11067 Little Red Riding Hood * DP

GY

11068 An Easy Task * Ad Hoc, Comp. Geometry

GY

11069 A Graph Problem * Math

GY

11070 ? * *

*

11071 ? * *

*

11072 ? * *

*

11073 ? * *

*

11074 Draw Grid * Simulation, String Processing

GY

11075 ? * *

*

11076 Add Again * Math

GY

11077 ? * *

*

11078 Open Credit System * Ad Hoc

GY

11079 ? * *

*

11080 ? * *

*

11081 ? * *

*

11082 ? * *

*

11083 ? * *

*

11084 ? * *

*

11085 Back to the 8-Queens * Ad Hoc

GY

11086 Composite Prime * Math

GY

11087 ? * *

*

11088 ? * *

*

11089 Fi-binary Number * Complete Search

GY

11090 ? * *

*

11091 ? * *

*

11092 ? * *

*

11093 Just Finish it up * DP

GY

11094 ? * *

*

11095 ? * *

*

11096 ? * *

*

11097 ? * *

*

11098 ? * *

*

11099 Next Same-Factored ? Math GY

Total hints in this volume: 44


11000 - Bee

The problem is a cloaked version of the Fibonacci sequence. For each n, the number of male bees is fibonacci(n+2)-1 and the total number of bees is fibonacci(n+3)-1.

11001 - Necklace

Given Vt and Vo, we need to maximize the length of the necklace. Assume the necklace has n rings, write the function of the length of the necklace. See the maxima, and the corresponding value of n.

11002 - Towards Zero

Use usd[i][j][k] (max bool usd[70][70][6000] ) to know whether a sum of k can be got when you reach (i,j) from (1,1). Since the sum can range from -3000 to 3000, I denote k accordingly. So usd[i][j][k] is true only when usd[i-1][j-1][l] is true and l+val[i][j]=k or usd[i-1][j][m] is true and m+val[i][j]=k. Complexity is N^2*6000.

11003 - Boxes

Define RC(Residual Capacity) [i][j] as the maximum load that can be stacked above a configuration using the first i boxes and of height exactly j. RC[i][j]= max( RC[i-1][j], min ( lc[i], RC[i-1][j-1] - w[i]) );

11005 - Cheapest Base

A simple problem of converting a number from base 10 to base [2,3,...36].

11008 - Anitimatter Ray Clearcutting

This is a DP problem. The state is the uncutted trees, and can be expressed by a bit string.
F[s]=1+min(F[s & (~L)] (L is a maximized set of trees which are located in a line, and S&L!=0)
The complexity is O(n^2*2^n), n is the number of trees.

11012 - Cosmic Cabbages

The distance between 2 points can be simplified with these 4 possibilities.
max(x[i]+y[i]+z[i])-min(x[j]+y[j]+z[j]);
max(x[i]+y[i]-z[i])-min(x[j]+y[j]-z[j]);
max(x[i]-y[i]+z[i])-min(x[j]-y[j]+z[j]);
max(x[i]-y[i]-z[i])-min(x[j]-y[j]-z[j]);
for all i and j.
and each case takes O(n) time. So the complexity becomes O(n), and the max value of the four cases is the answer.
Maintain a Max and Min for all these 4 values . Output the global max.

11015 - 05-32 Rendezvous

Given a graph of maximum 100 vertices, the idea is to find All Source Shortest Path. Use Floyd Warshall.

11019 - Matrix Matcher

A simple checking algorithm. Use scanf/printf for faster I/O.

11020 - Efficient Solutions

Use the C++ STL Set to solve a problem. Each time a gentlemen arrives, put him into set according to the rule.
LB < LA and CB <= CA, or
LB <= LA and CB < CA. WHEN B precedes A.
Once you insert into the set , output the rank using the "distance" function.

11022 - String Factoring

DP. Let SF[i][j] be the maximal factoring for string s[i-->j]. BC is SF[i][i]=1;
If there is a repeated string in s[i--->j], find the minimal length of repeated string say k. So SF[i][j]=SF[i][i+k-1];
else SF[i][j]=min(SF[i][j],SF[i][k]+SF[k+1][k]) i<=k<=(j-1).

11026 - A Grouping Problem

Here we need to find the sum of product of a k element subset given n elements.
Define C[m][k] as the sum of product of the first m element k element subsets.
C[m][k]= C[m-1][k]+C[m-1][k-1]*( Value of the mth element );

11028 - Sum of Product

Formula Check http://www.research.att.com/~njas/sequences/Seis.html

11029 - Leading and Trailing

1) To find the last 3 digits, use %1000 and fast exponentiation of POWER(n,k);
2) To find the first digits? . We can write n^k as 10 pow( klog10n ). Klog10n has an integer part i and a decimal part d.
Since n^k is pow(10,i)*pow(10,d) , pow(10,i) cannot give you the first 3 digits ( Why? ) . The first 3 digitsis the first 3 digits of pow(10,d)!

11031 - Looking for a Subset

Basically Longest Increasing Subsequence to be solved in O(n log n).

11032 - Function Overloading

1st Observation: Since sod(i) can be only from 1 to 63, we need to check only for a-1 to a-63 in the fun(a);
2nd Observation: Since we need to know for fun(a,b) , the number of numbers between a to b , that return -1( or equivalently the return value of not -1) from fun(a) : Hence we store this value in f[i]; the output will be f[b]-f[a-1];

11034 - Ferry Loading IV

Simple simulation. Count how many times the ferry should cater to the left shore, denote this vaue by l. Now, count how many times the ferry should cater to the right shore, denote this value by r. Final answer - printf("%d\n",max(2*l-1,2*r));

11038 - How Many 0's

http://www.algorithmist.com/index.php/UVa_11038

11039 - Building Designing

Greedy Strategy. Sort the red and blue buildings. Start with the building color with the least floor space. Keep alternatively picking the next color floor with the least greater area.

11040 - Add bricks in the wall

For the odd rows, the gaps between the given numbers can be filled using the expression a[i][j]=(a[i-2][j-1]-a[i][j-1]-a[i][j+1])/2;
and for the even rows the sum is calculated normally using a[i][j]=a[i+1][j]+a[i+1][j+1];

11042 - Complex, difficult and complicated

The only answers possible are 1,2,4 and TOO COMPLICATED. Think about it.

11044 - Searching for Nessy

A simple math problem : "cout<<( ((int)n/3) * ((int)m/3) )<<endl;"

11045 - My T-shirt suits me

A maximum matching problem.

a) Mark Source 0.Node 1 to M represent the M volunteers. Node (M+1) to (M+6) represent the T-shirts.Node (M+7) is the sink.
b) Connect Source to the M volunteers with cost 1. Connect all the T shirts to the sink with N/6. For each volunteer , connect the two shirt that fits him with cose 1.
Print the maxflow (Graph simulated).

11047 - The Scrooge Co Problem

A simple Floyd Warshall Implementation. To print the path store in p[i][j], the last but one vertex visited in the shortest path from i ---> j.

11054 - Wine trading in Gergovia

This is a greedy problem.
The problem is actually an array containing different numbers representing the wine.
The positive and negative means the demand and supply.
So we can greedily make it linear. That is make the first house 0. transport the supply or demand to the second.
And then, to the third.....At the same time, record down the moves required.
The greedy works because every move of the wine can be broken into the move between two consecutive houses.

11055 - Homogeneous squares

A math problem..
consider the simplest case, n=2, so a1+b2==a2+b1;
quite simple, consider the n=3, it is easy to see that, if and only if every 2*2 square in 3*3 is Homogeneous square.
more generally, by mathematical induction, we can prove that n*n is Homogeneous square if and only if every (n-1)*(n-1) is
Homogeneous square.
so we can conclude that if the square is Homogeneous, every sub 2*2 square satisfy the a1+b2==a2+b1.
the coding is quite easy.

11056 - Formula 1

A sorting problem. I just count the time by ms. convert all the time to millisecond and compare them (use long long is enough) right a cmp function such that if it is equal, sort by the name. use strcasecmp to compare string case insensitively.

11057 - Exact Sum

Use the sliding window technique: To find 2 numbers whose sum is equal to K from a sorted array.

Alternative: very simple adhoc problem. just brute force all solutions, find the solution. remember when having multisolution, output the one with the smallest difference.

11058 - Encoding

A string processing problem. First just read the string and the rule. Apply the later rule first. Just do the simulation you will get it.

11059 - Maximum Product

Brute force to find all sequence products: the input is considerably small.


This document, volC10.html, has been accessed 1623 times since 19-Feb-09 21:42:38 SGT. This is the 8th time it has been accessed today.

A total of 920 different hosts have accessed this document in the last 263 days; your host, 38.107.191.107, 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.

Alternative: A simple adhoc, as the input size is very small 18... so we just go through all possibilities...

11062 - Andy's Second Dictionary

Another string processing problem. First read in the string by lines , if the last one is - then change the - to 0, after read the string, reformat it. That is, if there is 0, delete it. So that the dis-ney will became dis0ney and disney. Split the word by token, add them into a set and use the iterator to output. Remember to convert all uppercase to lower.

11063 - B2-Sequence

Another simple search. As the input of each number is bounded. so the difference of the two numbers are bounded. Construct an array to store whether it appear before. Take note that if there consist of negative number, it is not a B2 sequence.

11064 - Number Theory

A math problem of number theory. We can compute the gcd(m,n) = m first, by computer all the divisor. by n=a1^b1*....ak^bk...number of divisor is (b1+1)* (b2+1)...(bk+1). Computer the gcd(m,n) = 1 by the Euler's totient function...see http://en.wikipedia.org/wiki/Euler%27s_totient_function. The coding is simple...

11067 - Little Red Riding Hood

Straight forward DP. The (i,j)is the sum of (i-1,j)+(i,j-1), the point which is possible to encounter the wolf is considered 0;

11068 - An Easy Task

Simple adhoc. Just compute the intersection of two lines. Note that the line can be parallel. Further more, the line many be vertical or horizontal..

11069 - A Graph Problem

A simple "DP". The formula is dp[i]=dp[i-1]+dp[i-5]; As the input is between 1 and 76. Better to pre-calculate all the results.

11074 - Draw Grid

Simple string simulation. Just follow the pattern... Note the output format...

11076 - Add Again

Adding all permutations is a math problem. We need to calculate how many times the digit will occur in the place. For each digit, the adding time for each digit is the (n-1)!/ k! where k is number of repeat of the digit. so just multiply the digit with the adding time. As the permutation, the number should be the same in every decimal place. So just make sure to add c/10 to the next decimal place. Output every decimal place.

11078 - Open Credit System

A ad hoc problem. Try to find the max difference between any two number in the sequence in O(n) time. If the current max if greater than the one, and the gap is greater than the max gap, update the max gap. If the current max is smaller than the one, update the current max. Do it for all numbers.

11085 - Back to the 8-Queens

This is another ad hoc problem. First just compute all the solutions for the 8 queen problem. Read the input and compare each input with each solution, and find the minimum move one.

11086 - Composite Prime

Composite prime. this is a math problem. Make the 4 as the first cprime. and do the same thing as the seive prime algorithm. If the number is not a prime and it is in the cprime list, then it is a composite prime.

11089 - Fi-binary Number

It is a problem about recursion. First we can recursively find the number of k-digit numbers. So given the input we can determine the numbers of digits the output should be. Then we can determine the first digit of the number. We can minus the number of k-digit number. The remaining number, we do it recursively. The base case is 1 and 2. Remember to consider the number of 0s to print when doing the recursion.

11093 - Just Finish it up

it is a recursion problem (or some sense DP)
the formula is
f[n]=p[n]-q[n];
for (int j=n-1;j>=1;j--)
  if (f[j+1]<=0) f[j]=f[j+1]+p[j]-q[j];
  else f[j]=p[j]-q[j];
temp=0;
min=2147483647;
ff[1]=0;
for (int j=1;j<=n-1;j++)
{
  temp=temp+p[j]-q[j];
  if (temp<min) min=temp;
  ff[j+1]=min;
}
fff[1]=totalgas-totalneed;
for (int j=2;j<=n;j++)
  fff[j]=fff[j-1]-p[j-1]+q[j-1];
the fff[j] is the one.
answer is min(f[j], ff[j]+fff[j])
if answer>0 then j is satisfied.

11099 - Next Same-Factored

This is a math problem. To avoid TLE we cannot brute force. For a give input we just get all the factors. And we create a queue. Adding all the numbers with the same factors into the queue. Find the minimum one which is greater than the input.