The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 5 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
1. Frogger
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who
is sitting on another stone. He plans to visit her, but since the water is dirty and full of
tourists' sunscreen, he wants to avoid swimming and instead reach her by jumping.
Unfortunately Fiona's stone is out of his jump range. Therefore Freddy considers to use other
stones as intermediate stops and reach her by a sequence of several small jumps.
To execute a given sequence of jumps, a frog's jump range obviously must be at least as
long as the longest jump occurring in the sequence.
The frog distance (humans also call it minimax distance) between two stones therefore is
defined as the minimum necessary jump range over all possible paths between the two
stones.
You are given the coordinates of Freddy's stone, Fiona's stone and all other stones in the
lake. Your job is to compute the frog distance between Freddy's and Fiona's stone.
Input Specification
The input file will contain one or more test cases. The first line of each test case will contain
the number of stones n ( 2
(0
stone #2 is Fiona's stone, the other n-2 stones are unoccupied. There's a blank line following
each test case. Input is terminated by a value of zero (0) for n.
Output Specification
For each test case, print a line saying ``Scenario #x" and a line saying ``Frog Distance = y"
where x is replaced by the test case number (they are numbered from 1) and y is replaced
by the appropriate real number, printed to three decimals. Put a blank line after each test
case, even after the last one.
Sample Input
2
00
34
3
17 4
19 4
18 5
0
Sample Output
Scenario #1
Frog Distance = 5.000
Scenario #2
Frog Distance = 1.414
2. Prime Path
The ministers of the cabinet were quite upset by the message from the Chief of Security
stating that they would all have to change the four-digit room numbers on their offices.
It is a matter of security to change such things every now and then, to keep the
enemy in the dark.
But look, I have chosen my number 1033 for good reasons. I am the Prime minister,
you know!
I know, so therefore your new number 8179 is also a prime. You will just have to
paste four new digits over the four old ones on your office door.
No,it’s not that simple. Suppose that I change the first digit to an 8, then the number
will read 8033 which is not a prime!
?
?
?
?
?
I see, being the prime minister you cannot stand having a non-prime number on your
door even for a few seconds.
Correct! So I must invent a scheme for going from 1033 to 8179 by a path of prime
numbers where only one digit is changed from one prime to the next prime. Now, the
minister of finance, who had been eavesdropping, intervened.
No unnecessary expenditure, please! I happen to know that the price of a digit is one
pound.
Hmm, in that case I need a computer program to minimize the cost. You don’t know
some very cheap software gurus, do you?
In fact, I do. You see, there is this programming contest going on
Help the prime minister to find the cheapest prime path between any two given four-digit
primes! The first digit must be nonzero, of course. Here is a solution in the case above.
1033
1733
3733
3739
3779
8779
8179
The cost of this solution is 6 pounds. Note that the digit 1 which got pasted over in step 2
can not be reused in the last step a new 1 must be purchased.
Input Format
One line with a positive number: the number of test cases (at most 100). Then for each test
case, one line with two numbers separated by a blank. Both numbers are four-digit primes
(without leading zeros).
Output Format
One line for each case, either with a number stating the minimal cost or containing the word
Impossible.
Sample Input
3
1033 8179
1373 8017
1033 1033
Sample Output
6
7
0
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll