Solution of 11057 - Exact Sum

Problem Description
source:https://uva.onlinejudge.org/external/110/11057.html

Peter received money from his parents this week and wants to spend it all buying books. But he does not read a book so fast, because he likes to enjoy every single word while he is reading. In this way, it takes him a week to finish a book. 
          As Peter receives money every two weeks, he decided to buy two books, then he can read them until receive more money. As he wishes to spend all the money, he should choose two books whose prices summed up are equal to the money that he has. It is a little bit difficult to find these books, so Peter asks your help to find them.

image

Solution of 299 - Train Swapping

Problem Description
source:https://uva.onlinejudge.org/external/2/299.html

At an old railway station, you may still encounter one of the last remaining “train swappers”. A train swapper is an employee of the railroad, whose sole job it is to rearrange the carriages of trains. 
        Once the carriages are arranged in the optimal order, all the train driver has to do, is drop the carriages off, one by one, at the stations for which the load is meant. 
        The title “train swapper” stems from the first person who performed this task, at a station close to a railway bridge. Instead of opening up vertically, the bridge rotated around a pillar in the center of the river. After rotating the bridge 90 degrees, boats could pass left or right. 
image

Solution of 11044 - Searching for Nessy

Problem Description
source:https://uva.onlinejudge.org/external/110/11044.html

The Loch Ness Monsteris a mysterious and unidentified animal said to inhabit Loch Ness, a large deep freshwater loch near the city of Inverness in northern Scotland. Nessie is usually categorized as a type of lake monster. 

http://en.wikipedia.org/wiki/Loch_Ness_Monster 

In July 2003, the BBC reported an extensive investigation of Loch Ness by a BBC team, using 600 separate sonar beams, found no trace of any “sea monster” (i.e., any large animal, known or unknown) in the loch. The BBC team concluded that Nessie does not exist. Now we want to repeat the experiment. 
      Given a grid of n rows and m columns representing the loch, 6 ≤ n, m ≤ 10000, find the minimum number s of sonar beams you must put in the square such that we can control every position in the grid, with the following conditions:

Solution of 11034 - Ferry Loading IV

Problem Description
source:https://uva.onlinejudge.org/external/110/11034.html

Before bridges were common, ferries were used to transport cars across rivers. River ferries, unlike their larger cousins, run on a guide line and are powered by the river’s current. Cars drive onto the ferry from one end, the ferry crosses the river, and the cars exit from the other end of the ferry. 
         There is an l-meter-long ferry that crosses the river. A car may arrive at either river bank to be transported by the ferry to the opposite bank. The ferry travels continuously back and forth between the banks so long as it is carrying a car or there is at least one car waiting at either bank. Whenever the ferry arrives at one of the banks, it unloads its cargo and loads up cars that are waiting to cross as long as they fit on its deck. The cars are loaded in the order of their arrival; ferry’s deck accommodates only one lane of cars. The ferry is initially on the left bank where it broke and it took quite some time to fix it. In the meantime, lines of cars formed on both banks that await to cross the river. 

Algorithm of 10970 - Big Chocolate

Problem Description Link
Algorithm:
This is a very simple problem. Just read this problem carefully.
To solve this problem you can follow this technique the minimum number of cuts needed to split the
 entire chocolate into unit size pieces is (m*n-1)
image

Solution of 10970 - Big Chocolate

Problem Description
source:https://uva.onlinejudge.org/external/109/10970.html

Mohammad 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 Mohammad 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. 

Algorithm of 10945 - Mother bear

Problem Description Link
Algorithm:

It is a simple problem . To solve this problem you can follow this technique.
1. to solve this problem just you get a string
2. after getting input you can check each character from string.
 if character is alpha numeric then you can put it into another array
and check the character is  alpha numeric and capital letter then you you can convert in small letter(Nb: all character small or capital in this logic all character are small).

image

Solution of 10945 - Mother bear

Problem Description
source:https://uva.onlinejudge.org/external/109/10945.html

Unforunately for our lazy “heroes”, the nuts were planted by an evil bear known as.. Dave, and they’ve fallen right into his trap. Dave is not just any bear, he’s a talking bear, but he can only understand sentences that are palindromes. While Larry was dazed and confused, Ryan figured this out, but need a way to make sure his sentences are palindromic. So he pulled out his trustly iPod, which thankfully have this program you wrote just for this purpose... or did you?

Algorithm of 10940 - Throwing cards away II

Problem Description Link
Algorithm:

This problem same as 10935 .
but if you use queue to solve this problem may be you get time limit exit so you can use any tricky method .

You can follow this algorithm:
image

Solution of 10940 - Throwing cards away II

Problem Description
source:https://uva.onlinejudge.org/external/109/10940.html


Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the deck: 
     Throw away the top card and move the card that is now on the top of the deck to the bottom of the deck. 
     Your task is to find the last, remaining card. 

Algorithm of 10935 - Throwing cards away I

Problem Description Link
Algorithm:

This is a simple problem just use queue.
Algorithm:
1. get input 1 to n in queue
2. loop until queue not empty
image

Solution of 10935 - Throwing cards away I

Problem Description
source:https://uva.onlinejudge.org/external/109/10935.html

Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the deck: 

     Throw away the top card and move the card that is now on the top of the deck to the bottom of the deck. 
     Your task is to find the sequence of discarded cards and the last, remaining card. 

Input 

Solution of 10921 - Find the Telephone

Problem Description
source:https://uva.onlinejudge.org/external/109/10921.html

In some places is common to remember a phone number associating its digits to letters. In this way the expression “MY LOVE” means 69 5683. Of course there are some problems, because some phone numbers can not form a word or a phrase and the digits 1 and 0 are not associated to any letter. Your task is to read an expression and find the corresponding phone number based on the table below. An expression is composed by the capital letters (A-Z), hyphens (-) and the numbers 1 and 0.

Algorithm of 10812 - Beat the Spread!

Problem Description Link
Algorithm:

To solve this problem you follow just simple trick.
 you get input a and b
sum=(a+b)/2;
diff=(a-b)/2;
image

Solution of 10812 - Beat the Spread!

Problem Description
source:https://uva.onlinejudge.org/external/108/10812.html

Superbowl Sunday is nearly here. In order to pass the time waiting for the half-time commercials and wardrobe malfunctions, the local hackers have organized a betting pool on the game. Members place their bets on the sum of the two final scores, or on the absolute difference between the two scores. 
      Given the winning numbers for each type of bet, can you deduce the final scores?

Solution of 10783 - Odd Sum

Problem Description
source:https://uva.onlinejudge.org/external/107/10783.html

Given a range [a, b], you are to find the summation of all the odd integers in this range. For example, the summation of all the odd integers in the range [3, 9] is 3 + 5 + 7 + 9 = 24.

Input 

There can be at multiple test cases. The first line of input gives you the number of test cases, T (1 ≤ T ≤ 100). Then T test cases follow. Each test case consists of 2 integers a and b (0 ≤ a ≤ b ≤ 100) in two separate lines. 

image

Solution of 10773 - Back to Intermediate Math

Problem Description
source:https://uva.onlinejudge.org/external/107/10773.html

Umm! So, you claim yourself as an intelligent one? Let me check. As, computer science students always insist on optimization whenever possible, I give you an elementary problem of math to optimize. 
        You are trying to cross a river of width d meters. You are given that, the river flows at v ms−1 and you know that you can speed up the boat in u ms−1 . There may be two goals how to cross the river: One goal (called fastest path) is to cross it in fastest time, and it does not matter how far the flow of the river takes the boat. The other goal (called shortest path) is to steer the boat in a direction so that the flow of the river doesn’t take the boat away, and the boat passes the river in a line perpendicular to the boarder of the river. Is it always possible to have two different paths, one to pass at shortest time and the other at shortest path? If possible then, what is the difference (Let P s) between the times needed to cross the river in the different ways?
image

Solution of 10696 - f91

Problem Description
source:https://uva.onlinejudge.org/external/106/10696.html

McCarthy is a famous theorician of computer science. In his work, he defined a recursive function, called f91, that takes as input a positive integer N and returns a positive integer defined as follows:
       • If N ≤ 100, then f91(N) = f91(f91(N + 11)); 
       • If N ≥ 101, then f91(N) = N − 10. 

Write a program, that computes McCarthy’s f91. 

image

Algorithm of 10394 - Twin Primes

Problem Description Link
Algorithm:


This is a simple problem but need more time than other problem.
you can follow this technique .
1. Firstly you need to generate prime in prime[] array up to max=20000000 before getting input.
image

Solution of 10394 - Twin Primes

Problem Description
source:https://uva.onlinejudge.org/external/103/10394.html

Twin primes are pairs of primes of the form (p, p + 2). The term “twin prime” was coined by Paul Stckel (1892-1919). The first few twin primes are (3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43). In this problem you are asked to find out the S-th twin prime pair where S is an integer that will be given in the input.

Input 

The input will contain less than 10001 lines of input. Each line contains an integers S (1 ≤ S ≤ 100000), which is the serial number of a twin prime pair. Input file is terminated by end of file. 
image

Solution of 483 - Word Scramble

Problem Description
source:https://uva.onlinejudge.org/external/4/483.html

Write a program that will reverse the letters in each of a sequence of words while preserving the order of the words themselves. 

Input 

The input file will consist of several lines of several words. Words are contiguous stretches of printable characters delimited by white space. 

image

Algorithm of 10591 - Happy Number

Problem Description Link
Algorithm:
Iterating this sum-of-squared-digits map always eventually
 reaches one of the 10 numbers 0, 1, 4, 16, 20, 37, 42, 58, 89, or 145
image

Solution of 10591 - Happy Number

Problem Description
source:https://uva.onlinejudge.org/external/105/10591.html

Let the sum of the square of the digits of a positive integer S0 be represented by S1. In a similar way, let the sum of the squares of the digits of S1 be represented by S2 and so on. If Si = 1 for some i ≥ 1, then the original integer S0 is said to be Happy number. A number, which is not happy, is called Unhappy number. For example 7 is a Happy number since 7 → 49 → 97 → 130 → 10 → 1 and 4 is an Unhappy number since 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4.

Input 

The input consists of several test cases, the number of which you are given in the first line of the input. Each test case consists of one line containing a single positive integer N smaller than 109 .

image

Solution of 10487 - Closest Sums

Problem Description
source:https://uva.onlinejudge.org/external/104/10487.html

Given is a set of integers and then a sequence of queries. A query gives you a number and asks to find a sum of two distinct numbers from the set, which is closest to the query number.

Input 

Input contains multiple cases. 
       Each case starts with an integer n (1 < n ≤ 1000), which indicates, how many numbers are in the set of integer. Next n lines contain n numbers. Of course there is only one number in a single line. The next line contains a positive integer m giving the number of queries, 0 < m < 25. The next m lines contain an integer of the query, one per line. 
      Input is terminated by a case whose n = 0. Surely, this case needs no processing. 

image

Algorithm of 10487 - Closest Sums

Problem Description Link
Algorithm:
To solve this problem you can follow this technique
1. first you need input for n and n integer value
2. then generate all possible sum of n integers
3. then get input for m and m distinct integer query
image

Solution of 10469 - To Carry or not to Carry

Problem Description
source:https://uva.onlinejudge.org/external/104/10469.html

6+9=15 seems okay. But how come 4+6=2? You see, Mofiz had worked hard throughout his digital logic course, but when he was asked to implement a 32 bit adder for the laboratory exam, he did some mistake in the design part. After tracing the design for half an hour, he found his flaw!! He was doing bitwise addition but his carry bit always had zero output. Thus, 

      4 = 00000000 00000000 00000000 00000100 
     +6= 00000000 00000000 00000000 00000110
       --------------------------------------------------------
      2 = 00000000 00000000 00000000 00000010 

Solution of 10008 - What's Cryptanalysis?

Problem Description
source:http://uva.onlinejudge.org/external/100/10008.html

Cryptanalysis is the process of breaking someone else’s cryptographic writing. This sometimes involves some kind of statistical analysis of a passage of (encrypted) text. Your task is to write a program which performs a simple analysis of a given text. 

Input 

The first line of input contains a single positive decimal integer n. This is the number of lines which follow in the input. The next n lines will contain zero or more characters (possibly including whitespace). This is the text which must be analyzed.

image