The post SPOJ Problem 4408. Build a Fence (FENCE1) Solution appeared first on Dreamshire.

]]>4408. Build a Fence

There is a wall in your backyard. It is so long that you can’t see its endpoints. You want to build a fence of length L such that the area enclosed between the wall and the fence is maximized. The fence can be of arbitrary shape, but only its two endpoints may touch the wall.

**Input Specification**

The input consists of several test cases.

For every test case, there is only one integer L (1<=L<=100), indicating the length of the fence. The input ends with L=0.

**Output Specification**

For each test case, output one line containing the largest area. Your answer should be rounded to 2 digits after the decimal point.

**Sample Input**

1

7

0

**Sample Output**

0.16

7.80

**Solution** (File: 4408.py)

Use this link to get the Project Euler Solution Python 2.7 source.

**Comments**

The test cases are qualified to match the input specification.

The post SPOJ Problem 4408. Build a Fence (FENCE1) Solution appeared first on Dreamshire.

]]>The post SPOJ Problem 42. Adding Reversed Numbers (ADDREV) appeared first on Dreamshire.

]]>**Description**

42. Adding Reversed Numbers

The Antique Comedians of Malidinesia prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies. Therefore the dramatic advisor of ACM has decided to transfigure some tragedies into comedies. Obviously, this work is very hard because the basic sense of the play must be kept intact, although all the things change to their opposites. For example the numbers: if any number appears in the tragedy, it must be converted to its reversed form before being accepted into the comedy play.

Reversed number is a number written in arabic numerals but the order of digits is reversed. The first digit becomes last and vice versa. For example, if the main hero had 1245 strawberries in the tragedy, he has 5421 of them now. Note that all the leading zeros are omitted. That means if the number ends with a zero, the zero is lost by reversing (e.g. 1200 gives 21). Also note that the reversed number never has any trailing zeros.

ACM needs to calculate with reversed numbers. Your task is to add two reversed numbers and output their reversed sum. Of course, the result is not unique because any particular number is a reversed form of several numbers (e.g. 21 could be 12, 120 or 1200 before reversing). Thus we must assume that no zeros were lost by reversing (e.g. assume that the original number was 12).

**Input Specification**

The input consists of N cases (equal to about 10000). The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly one line with two positive integers separated by space. These are the reversed numbers you are to add.

**Output Specification**

For each case, print exactly one line containing only one integer – the reversed sum of two reversed numbers. Omit any leading zeros in the output.

**Sample Input**

3

24 1

4358 754

305 794

**Sample Output**

34

1998

1

**Solution** (File: 42.py)

**Comments**

The test cases are qualified to match the input specification.

The post SPOJ Problem 42. Adding Reversed Numbers (ADDREV) appeared first on Dreamshire.

]]>The post SPOJ Problem 11. Factorial (FCTRL) Trailing zeros in factorials appeared first on Dreamshire.

]]>SPOJ 11 Factorial (FCTRL) Trailing zeros in factorials

The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to the BTS with the strongest signal (in a little simplified view). Of course, BTSes need some attention and technicians need to check their function periodically.

ACM technicians faced a very interesting problem recently. Given a set of BTSes to visit, they needed to find the shortest path to visit all of the given points and return back to the central company building. Programmers have spent several months studying this problem but with no results. They were unable to find the solution fast enough. After a long time, one of the programmers found this problem in a conference article. Unfortunately, he found that the problem is so called “Travelling Salesman Problem” and it is very hard to solve. If we have N BTSes to be visited, we can visit them in any order, giving us N! possibilities to examine. The function expressing that number is called factorial and can be computed as a product 1×2×3×4×…×N. The number is very high even for a relatively small N.

The programmers understood they had no chance to solve the problem. But because they have already received the research grant from the government, they needed to continue with their studies and produce at least some results. So they started to study behaviour of the factorial function.

For example, they defined the function Z. For any positive integer N, Z(N) is the number of zeros at the end of the decimal form of number N!. They noticed that this function never decreases. If we have two numbers N1 < N2, then Z(N1) ≤ Z(N2). It is because we can never “lose” any trailing zero by multiplying by any positive number. We can only get new and new zeros. The function Z is very interesting, so we need a computer program that can determine its value efficiently.

**Input Specification**

There is a single positive integer T on the first line of input (equal to about 100000). It stands for the number of numbers to follow. Then there are T lines, each containing exactly one positive integer number N, 1 ≤ N ≤ 1000000000.

**Output Specification**

For every number N, output a single line containing the single non-negative integer Z(N).

**Sample Input:**

6

3

60

100

1024

23456

8735373

**Sample Output:**

0

14

24

253

5861

2183837

**Ancillary Files**

Input file: fctrl.in

Output file: fctrl.out

**SPOJ 11 Factorial (FCTRL) Solution** in Python 2.7 (File: 11.py)

**Usage Directions**

Run from cmd prompt as: python 11.py < fctrl.in > my_fctrl.out

and compare my_ fctrl.out to fctrl.out. Submit the program to the SPOJ server at the link provided under the description.

The test cases are pre-qualified to match the input specification.

*Trailing zeros in factorials* update 6/30/2014

The post SPOJ Problem 11. Factorial (FCTRL) Trailing zeros in factorials appeared first on Dreamshire.

]]>The post SPOJ Problem 1681. Cylinder Volume (CYLINDER) Solution appeared first on Dreamshire.

]]>**CYlinder Volume Description**

1681. Cylinder volume

Cylinder Volume: Using a sheet of paper and scissors, you can cut out two faces to form a cylinder in the following way:

- Cut the paper horizontally (parallel to the shorter side) to get two rectangular parts.
- From the first part, cut out a circle of maximum radius. The circle will form the bottom of the cylinder.
- Roll the second part up in such a way that it has a perimeter of equal length with the circle’s circumference, and attach one end of the roll to the circle. Note that the roll may have some overlapping parts in order to get the required length of the perimeter.

Given the dimensions of the sheet of paper, can you calculate the biggest possible volume of a cylinder which can be constructed using the procedure described above?

**Input Specification**

The input consists of several test cases. Each test case consists of two numbers w and h (1 ≤ w ≤ h ≤ 100), which indicate the width and height of the sheet of paper.

The last test case is followed by a line containing two zeros.

**Output Specification**

For each test case, print one line with the biggest possible volume of the cylinder. Round this number to 3 places after the decimal point.

**Sample Input**

10 10

10 50

10 30

0 0

**Sample Output**

54.247

785.398

412.095

In the first case, the optimal cylinder has a radius of about 1.591549, in the second case, the optimal cylinder has a radius of 5, and in the third case, the optimal cylinder has a radius of about 3.621795.

**Ancillary Files**

Input file: cylinder.in

Output file: cylinder.out

**Solution** (File: 1681.py)

**Comments**

Run from cmd prompt as: python 1681.py < cylinder.in > my_cylinder.out

and compare my_ cylinder.out to cylinder.out. Submit the program to the SPOJ server at the link provided under the description.

The test cases are qualified to match the input specification.

The post SPOJ Problem 1681. Cylinder Volume (CYLINDER) Solution appeared first on Dreamshire.

]]>