Professional Documents
Culture Documents
Assignment A1 1
Assignment A1 1
Assignment A1 1
1) Intersection Point:
(x2,y2)
(x,y)
(x1,y1)
(x3,y3)
Input: eight floating point numbers: x1,y1,x2,y2,x3,y3,x4,y4 , where (x1,y1) and (x2,y2)
are two distinct points lying on one straight line and (x3,y3) and (x4,y4) are two distinct
points lying on the other straight line. If the lines are parallel or same, the answer will be
“NO SOLUTION”, if not the answer should be (x,y) where (x,y) is the intersecting point
of the two straight lines.
Sample Output 1: 0 0
Mr. Petuk has recently visited Switzerland. As he loves his friends very much, he decided
to buy some chocolate for them, but as this fine chocolate is very expensive(You know
Mr. Petuk is a little BIT stingy!), he could only afford buying one chocolate, albeit a very
big one (part of it can be seen in figure 1) for all of them as a souvenir. Now, he wants to
give each of his friends exactly one part of this chocolate and as he believes all human
beings are equal (!), he wants to split it into equal parts.
The chocolate is a rectangle constructed from unit-sized squares. You can assume that
Mr. Petuk has also friends waiting to receive their piece of chocolate. To split the
chocolate, Mr. Petuk can cut it in vertical or horizontal direction (through the lines that
separate the squares). Then, he should do the same with each part separately until he
reaches unit size pieces of chocolate. Unfortunately, because he is a little lazy, he wants
to use the minimum number of cuts required to accomplish this task. Your goal is to tell
him the minimum number of cuts needed to split all of the chocolate squares apart.
Input: Two integers: M and N, where M is the number of rows and M is the number of
columns of the chocolate.
Output: One integer X, where X is the minimum cuts needed to split all of the chocolate
apart.
Sample Input 1: 2 1
Sample Output 1: 1
Sample Input 2: 2 3
Sample Output 2: 5