Solution of 834 - Continued Fractions

Problem Description
source:https://uva.onlinejudge.org/external/8/834.html

Let b0, b1, b2, . . . , bn be integers with bk > 0 for k > 0. The continued fraction of order n with coeficients b1, b2, . . . , bn and the initial term b0 is defined by the following expression

which can be abbreviated as [b0; b1, . . . , bn]. An example of a continued fraction of order n = 3 is [2; 3, 1, 4]. This is equivalent to 

Algorithm of 579 - ClockHands

Problem Description Link

This is a calculation of the angle between the minute hand and the hour hand on a regular analog clock.
To solve this problem you can follow this stapes:
image

Solution of 579 - ClockHands

Problem Description
source:https://uva.onlinejudge.org/external/5/579.html

The medieval interest in mechanical contrivances is well illustrated by the development of the mechanical clock, the oldest of which is driven by weights and controlled by a verge, an oscillating arm engaging with a gear wheel. It dates back to 1386.
    Clocks driven by springs had appeared by the mid-15th century, making it possible to con- struct more compact mechanisms and preparing the way for the portable clock.
    English spring-driven pendulum clocks were first commonly kept on a small wall bracket and later on a shelf. Many bracket clocks contained a drawer to hold the winding key. The earliest bracket clocks, made for a period after 1660, were of architectural design, with pillars at the sides and a pediment on top.
     In 17th- and 18th-century France, the table clock became an object of monumental design, the best examples of which are minor works of sculpture
image

Algorithm of 575 - Skew Binary

Problem Description Link

This is a simple problem . only convert skew value to decimal value.
You can follow this stapes:
1. Get input string for skew value.
    (N.B: Input is string because input value range may greater than any type of value ie, int,... But
          result range in 2^31-1)
2. determine the length of input value.
3. under for loop i=0 to length-1
       decimalvalue+=(input[i]-48)*(pow(2,length-i)-1);
4. finally print the value of decimalvalue.
ie.
    input=10120
       length=5 so process is
    =1*(2^5-1)+0*(2^4-1)+1*(2^3-1)+2*(2^2-1)+0*(2^1-1)
    =31+0+7+6+0
    = 44
 so 44 is equivalent decimal value.

   
image

Solution of 575 - Skew Binary

Problem Description
source:httpa://uva.onlinejudge.org/external/5/575.html

When a number is expressed in decimal, the k-th digit represents a multiple of 10k . (Digits are numbered from right to left, where the least significant digit is number 0.) For example,

Algorithm of 694 - The Collatz Sequence

Problem Description Link

This is a simple problem . Just follow  this stapes:

Step 1:
    Choose an arbitrary positive integer A as the first item in the sequence.
Step 2:
    If A = 1 then stop.
Step 3:
    If A is even, then replace A by A / 2 and go to step 2.
Step 4:
    If A is odd, then replace A by 3 * A + 1 and go to step 2.

[You can use long long int data type ]

Solution Link
image

Solution of 694 - The Collatz Sequence

Problem Description
source:https://uva.onlinejudge.org/external/6/694.html

An algorithm given by Lothar Collatz produces sequences of integers, and is described as follows: 

Step 1: Choose an arbitrary positive integer A as the first item in the sequence. 
Step 2: If A = 1 then stop. 
Step 3: If A is even, then replace A by A/2 and go to step 2. 
Step 4: If A is odd, then replace A by 3 ∗ A + 1 and go to step 2. 

It has been shown that this algorithm will always stop (in step 2) for initial values of A as large as 109 , but some values of A encountered in the sequence may exceed the size of an integer on many computers. In this problem we want to determine the length of the sequence that includes all values produced until either the algorithm stops (in step 2), or a value larger than some specified limit would be produced (in step 4). 

image

Algorithm of 673 - Parentheses Balance

Problem Description Link
This problem is a easy problem. You can solve this problem using stack just follow this stapes
1. get input string for parenthesis.
2. Check, input is opening bracket then push in stack.
3. if  input is closing bracket then compare with top of the stack element
       if valid expression then input and stack top element same type opening and closing bracket
         ie. input= ")" then top= "(" or input= "]" then top= "["

image

Solution of 673 - Parentheses Balance

Problem Description
source:https://uva.onlinejudge.org/external/6/673.html

You are given a string consisting of parentheses () and []. A string of this type is said to be correct: 

(a) if it is the empty string 
(b) if A and B are correct, AB is correct, 
(c) if A is correct, (A) and [A] is correct. 

Write a program that takes a sequence of strings of this type and check their correctness. Your program can assume that the maximum string length is 128.

image

Algorithm of 591 - Box of Bricks

Problem Description Link

It is a simple problem read carefully and solve easilly .
one condition for print output
ie.
printf("Set #%ld\n",k);
printf("The minimum number of moves is %ld.\n\n",result);
image

Solution of 591 - Box of Bricks

Problem Description
source:https://uva.onlinejudge.org/external/5/591.html

Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stacks of different height. “Look, I’ve built a wall!”, he tells his older sister Alice. “Nah, you should make all stacks the same height. Then you would have a real wall.”, she retorts. After a little con- sideration, Bob sees that she is right. So he sets out to rearrange the bricks, one by one, such that all stacks are the same height afterwards. But since Bob is lazy he wants to do this with the minimum number of bricks moved. Can you help?

Algorithm of 621 - Secret Research

Problem Description Link
Actually this problem can be very easy once you know what it means (or when you read this hint).
How to know which output we have to give for each input? The answer is simple:

Positive when S is exactly "1","4",or "78"
Negative when the last two digits of S are exactly "35"
Experiment failed if the first digit of S is exactly "9" and the last one digit of S is exactly "4"
Experiment not completed if the first three digits are exactly "190"
image

Solution of 621 - Secret Research

Problem Description
source:https://uva.onlinejudge.org/external/6/621.html

At a certain laboratory results of secret research are thoroughly encrypted. A result of a single experiment is stored as an information of its completion:
      ‘positive result’, ‘negative result’, ‘experiment failed’ or ‘experiment not completed’
      The encrypted result constitutes a string of digits S, which may take one of the following forms:
        • positive result S = 1 or S = 4 or S = 78
        • negative result S = S35
        • experiment failed S = 9S4
        • experiment not completed S = 190S

(A sample result S35 means that if we add digits 35 from the right hand side to a digit sequence then we shall get the digit sequence corresponding to a failed experiment)
      You are to write a program which decrypts given sequences of digits.

image

Algorithm of 616 - Coconuts, Revisited

Problem Description Link

You can solve this problem using many method.
One condition is the
      If n is the number of people, then
           (n^n-n+1) is the number of coconuts.
you can get idea from this condition.
You can see solution
image

Solution of 616 - Coconuts, Revisited

Problem Description
source:https://uva.onlinejudge.org/external/6/616.html

The short story titled Coconuts, by Ben Ames Williams, appeared in the Saturday Evening Post on October 9, 1926. The story tells about five men and a monkey who were shipwrecked on an island. They spent the first night gathering coconuts. During the night, one man woke up and decided to take his share of the coconuts. He divided them into five piles. One coconut was left over so he gave it to the monkey, then hid his share and went back to sleep.
    Soon a second man woke up and did the same thing. After dividing the coconuts into five piles, one coconut was left over which he gave to the monkey. He then hid his share and went back to bed. The third, fourth, and fifth man followed exactly the same procedure. The next morning, after they all woke up, they divided the remaining coconuts into five equal shares. This time no coconuts were left over.
image