The Fundation: Logic & Proof – 01

Document (.doc)
Document (.pdf)

Advertisements
| Leave a comment

Google Form Test

| Leave a comment

10116: Robot Motion

P10116

A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions are

N north (up the page)
S south (down the page)
E east (to the right on the page)
W west (to the left on the page)

For example, suppose the robot starts on the north (top) side of Grid 1 and starts south (down). The path the robot follows is shown. The robot goes through 10 instructions in the grid before leaving the grid.

Compare what happens in Grid 2: the robot goes through 3 instructions only once, and then starts a loop through 8 instructions, and never exits.

You are to write a program that determines how long it takes a robot to get out of the grid or how the robot loops around.

There will be one or more grids for robots to navigate. The data for each is in the following form. On the first line are three integers separated by blanks: the number of rows in the grid, the number of columns in the grid, and the number of the column in which the robot enters from the north. The possible entry columns are numbered starting with one at the left. Then come the rows of the direction instructions. Each grid will have at least one and at most 10 rows and columns of instructions. The lines of instructions contain only the characters N, S, E, or W with no blanks. The end of input is indicated by a row containing 0 0 0.

For each grid in the input there is one line of output. Either the robot follows a certain number of instructions and exits the grid on any one the four sides or else the robot follows the instructions on a certain number of locations once, and then the instructions on some number of locations repeatedly. The sample input below corresponds to the two grids above and illustrates the two forms of output. The word “step” is always immediately followed by “(s)” whether or not the number before it is 1.

Example input:

3 6 5

NEESWE

WWWESS

SNWWWW

4 5 1

SESWE

EESNW

NWEEN

EWSEN

0 0 0

Example output:

10 step(s) to exit

3 step(s) before a loop of 8 step(s)

Tips:download

  1. First you have to input correctly.
  2. Take two array on is indicate input array other array element represent movement number.
  3. If out of col or row then only print count step
  4. Otherwise count -arry count current position value -1
  5. And count= count-loop count;
  6. End
Posted in ACM: graph | Tagged | Leave a comment

10137: The Trip

A number of students are members of a club that travels annually to exotic locations. Their destinations in the past have included Indianapolis, Phoenix, Nashville, Philadelphia, San Jose, and Atlanta. This spring they are planning a trip to Eindhoven.

The group agrees in advance to share expenses equally, but it is not practical to have them share every expense as it occurs. So individuals in the group pay for particular things, like meals, hotels, taxi rides, plane tickets, etc. After the trip, each student’s expenses are tallied and money is exchanged so that the net cost to each is the same, to within one cent. In the past, this money exchange has been tedious and time consuming. Your job is to compute, from a list of expenses, the minimum amount of money that must change hands in order to equalize (within a cent) all the students’ costs.

The Input

Standard input will contain the information for several trips. The information for each trip consists of a line containing a positive integer, n, the number of students on the trip, followed by n lines of input, each containing the amount, in dollars and cents, spent by a student. There are no more than 1000 students and no student spent more than $10,000.00. A single line containing 0 follows the information for the last trip.

The Output

For each trip, output a line stating the total amount of money, in dollars and cents, that must be exchanged to equalize the students’ costs.

Sample Input

 

3

10.00

20.00

30.00

4

15.00

15.01

3.00

3.01

0

Output for Sample Input

 

$10.00

$11.99

Tips:download

1.
If (currentStudentPayment > averagePayment)
   positiveDifference += currentStudentPayment - averagePayment;
Else
   negativeDifference += averagePayment - currentStudentPayment;

if(negativeDifference > positiveDifference)
   return negativeDifference
else
   return positiveDifference
 
2.  Here negative or positive difference must be int which is the tic of this problem....
Posted in ACM: Greedy Conversion | Tagged , | Leave a comment

10041: Vito’s family

Background

The world-known gangster Vito Deadstone is moving to New York. He has a very big family there, all of them living in Lamafia Avenue. Since he will visit all his relatives very often, he is trying to find a house close to them.

Problem

Vito wants to minimize the total distance to all of them and has blackmailed you to write a program that solves his problem.

Input

The input consists of several test cases. The first line contains the number of test cases.

For each test case you will be given the integer number of relatives r ( 0 < r < 500) and the street numbers (also integers) where they live ( 0 < si < 30000 ). Note that several relatives could live in the same street number.

Output

For each test case your program must write the minimal sum of distances from the optimal Vito’s house to each one of his relatives. The distance between two street numbers si and sj is dij= |sisj|.

Sample Input

2

2 2 4

3 2 4 6

Sample Output

2

4

Tics:download

1.  Sort the street number

2.  Find median

3.  Find summation of distance from median to street number i.e dis+=|median-si|


Posted in ACM: Ad Hoc | Tagged | Leave a comment

How Set up Ubuntu(desktop) ?

Ubuntu System Requirements:

Download the Document File from here: note

Before installing Ubuntu, you should also check your computer against the hardware requirements. The system requirements for Ubuntu are as follows:

  • 700 MHz or better processor
  • 3GB of available disk space
  • 256MB of memory (RAM)
  • CD-ROM drive
  • Ethernet interface
  • VGA graphics interface

Step-1:

Insert your Ubuntu install CD into your system and boot from it. First we have to select language. Then press enter key.

Image006

Step2:

Then we see the bellow figure and select Install to the hard disk:

Image007

Step3:

select  “Install Ubuntu” , then press enter key. Then we found a windows ,where we saw that data is read from CD dreive. The following figure is found:

Image008

Select the language. We can verify the language by typing under the text area.  Then we click on forward button which was located under the window.

Step 4: Next, we set the location . we set Asia for region and Dhaka for city. Then we forward the next step.

Step 5:  Set key board layout:

In this step, default keyboard layout is given as USA. We can select other keyboard layout as user like .Under the window, we found a text area to type and test our keyboard layout. Then we forward the next step.

Step 6: prepare disk space:

We found some option like:

  • Install them side by side, choosing between them each startup.
  • Use the entire disk.
  • Use the largest continuous free space.
  • Specify partition manually.

If we chose first, then ubuntu operating system is set up side by side and user has to choose one of them when computer starts. If we select second option then Ubuntu is setup by deleting exist operating system. If we select third option then it setup into the drive which free space is large. User can setup manually by selecting fourth option. Figure is given below:

Image009

Forward the step.

Step 7: partition is started. Select the most free space drive and double click on it. Figure is given below:

Image011

Image012

“Edit partition” window was opened. Select “Ext2 file System”( by default ,we foundà”do not use the partition”), then select the ‘/’ for mount point text area. Then click forward. We found “Do you want to return to the partition menu” window. We Clicked continue to precede installation.

Image013

Step 8:

Type in your real name, your desired username along with a password, and click on Forward: Figure as following

Image014

Then we found the following window, where we select the other software to install or migration. Then Click forward.

.Image015

Step 9:

The next screen shows us a summary of the installation settings. Click on Install to start the installation:

Image017

Afterwards, Ubuntu is being installed. This can take a few minutes, so be patient:

After the installation, we will be asked to reboot the system. Click on Restart now:

Image018

Remove the Ubuntu CD and press ENTER to boot into our new Ubuntu system:

Our new Ubuntu system starts. Log in to the desktop with the username and password we provided during the installation:

This is our new desktop looks:

Posted in Linux | Tagged | Leave a comment

SWAP TWO VARIABLE WITHOUT THIRD VARIABLE

Do you Know how to swap two variable without third variable?


Answer:
a=10,b=20;
a=^b^=a^=b;//it execute from left a=a^b;b=b^a;a=a^b
//now a=20;b=10
b=a+b-(a=b);//execute from right b=20+10-10=20; a=b=10;
//now a=10 b=20
b=(a*b)/(a=b); //similarly b=10*20/20; a=b=20;
//now a=20 b=10

Any wrong!

Do you Know how to swap three variable without extra variable?


Answer:
a = a + b + c;
b = a – (b + c);//b=a
c = a – (b + c);//c=b here b mean initial b, in operation b=a
a = a – (b + c);//a=c here c mean initial b, in operation b=a,c=b

Continue reading

Posted in ALGORITHM | Tagged , | Leave a comment