Showing posts with label Volume V. Show all posts
Showing posts with label Volume V. Show all posts

Solution of 543 - Goldbach's Conjecture

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

In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture:
       Every number greater than 2 can be written as the sum of three prime numbers. 
       Goldbach was considering 1 as a primer number, a convention that is no longer followed. Later on, Euler re-expressed the conjecture as:
       Every even number greater than or equal to 4 can be expressed as the sum of two prime numbers.

For example: 

    • 8 = 3 + 5. Both 3 and 5 are odd prime numbers.
    • 20 = 3 + 17 = 7 + 13.
    • 42 = 5 + 37 = 11 + 31 = 13 + 29 = 19 + 23.

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

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,

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?

Solution of 555 - Bridge Hands

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

Many games, such as Bridge, involve dealing a standard deck of 52 cards to 4 players, so each receives 13 cards. Good players can then play with the hand as it is dealt, but most ordinary players will need to sort it, firstly by suit, and then by rank within suit. 
     There is no fixed ranking of the suits for this purpose, but it is useful to alternate the colours, so we will presume the following ordering: ♣ < ♢ < ♠ < ♡. (Note that from now on we will use the more conventional ‘C’, ‘D’, ‘S’, ‘H’ for CLUBS, DIAMONDS, SPADES and HEARTS). Within a suit Ace is high, so the ordering is 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < Q < K < A.

Solution of 551 - Nesting a Bunch of Brackets

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

In this problem we consider expressions containing brackets that are properly nested. These expressions are obtained by juxtaposition of properly netsted expressions in a pair of matching brackets, the left one an opening and the right one a closing bracket.
        ( a + $ ( b = ) ( a ) ) is properly nested 
        ( a + $ ) b = ) ( a ( ) is not 

In this problem we have several pairs of brackets, so we have to impose a second condition on the expression: the matching brackets should be of the same kind. Consequently ‘(())’ is OK, but ‘([))’ is not. The pairs of brackets are:

(   ) 
[   ] 
{   } 
<   > 
(*   *)  

image

Solution of 541 - Error Correction

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

A boolean matrix has the parity property when each row and each column has an even sum, i.e. contains an even number of bits which are set. Here’s a 4 × 4 matrix which has the parity property: 

1 0 1 0 
0 0 0 0 
1 1 1 1 
0 1 0 1 

    The sums of the rows are 2, 0, 4 and 2. The sums of the columns are 2, 2, 2 and 2. 
    Your job is to write a program that reads in a matrix and checks if it has the parity property. If not, your program should check if the parity property can be established by changing only one bit. If this is not possible either, the matrix should be classified as corrupt. 

image