IEEE-VESIT ONLINE PROGRAMMING CONTEST

 



Instructions :


Dear Programmer,

There r 7 problems in all for u here. They r categorized  in 4 categories :

1)Easy (E) (10 pts.)
2)Moderate (M)(30 pts.)
3)Tough (T) (50 pts.)
4)Impossible (I) (100 pts.)

There r 2E, 2M, 2T and 1I problems.

Try to solve as many problems as u can so that u can score maximum marks ,
but there is a catch. In case of a tie the team which has solved a problem
carrying more marks will win.

Eg. : 10+50=60;  30+30=60.

In this case, the first team wins.

Also, the inputs will be taken only in the form specified in the
question,and please clear ur screens as soon as the program is executed.

So get cracking now, but don't crack under the pressure ; ALL THE BEST !!!

E1)Find the distance

Given a rectangle and a point, report the distance from the point to the
nearest point on the perimeter of the rectangle.

Each set of data consists of the two corners of a rectangle, followed by
coordinates (x,y) of a point p.
For each input, print the distance from p to the closest spot on the
perimeter of the rectangle.

Sample Input:

  Enter co-ordinates of top left hand corner : 2   4

Enter co-ordinates of bottom right hand corner : 10   10

Enter co-ordinates of p :  5   8

Sample Output:

  Output 1: 2


E2)Treasure Island

You are at the center of IEEE Island and you'll be given directions to the
buried treasure. The directions will be specified as ordered pairs
representing the distance (in miles) and the direction (in degrees) to
travel. All of the directions will be multiples of
30 or 45 degrees. An angle of 0 means due east, an angle of 90 is due north,
whereas an angle of -45 is southeast. Your job is to report the location of
the hidden treasure.

For example, suppose you were given the directions (5, 45) and (4, -30).
This means to travel 5 miles in the direction of 45
degrees, which takes you to (3.535, 3.535). From there, you head 4 miles in
a southeasterly direction, which takes you to (6.999, 1.535).

You are not allowed to use any trigonometry functions (sin, cos, etc.).

Sample Input:

Enter N : 2
Enter distance,dirn : 5   45
Enter distance,dirn : 4   -30

Sample Output:

  The treasure is buried at 6.999, 1.535

M1)Recurring decimals


Write a program that will accept a fraction of the form N/D, where N is the
numerator and D is the denominator, that prints out
the decimal representation. If the decimal representation has a repeating
sequence of digits, it should be indicated by enclosing it
in brackets. For example, 1/3 = .33333333...is denoted as .(3), and 41/333 =
.123123123...is denoted as .(123).

Typical conversions are:

1/3     =   .(3)
22/5    =  4.4
1/7     =   .(142857)
3/8     =   .375
45/56   =   .803(571428)


Sample Run

ENTER N,D : 1  7

1/7 = 0.(142857)

ENTER N,D : 16  7

16/7 = 2.(285714)



M2)THE GRI(N)D

Given a 4*4 grid  N of the foll. form :

1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7

Following operations can be performed on the grid :

1)rxchg r1 r2 : exchange the rows r1 and r2

2)cxchg c1 c2 : exchange the columns c1 and c2

3)rotouterclock : rotate the elements on the periphery 1 position clockwise

Eg. : If applied to the grid N, grid becomes :

12 1 2 3
11 13 14 4
10 16 15 5
9 8 7 6

4)rotinnerclock : rotate the inner square 1 position clockwise :

Eg. : If applied to the above grid , grid becomes :

1 2 3 4
12 16 13 5
11 15 14 6
10 9 8 7

5)rotouteranti : rotate the elements on the periphery 1 position
anti-clockwise

6)rotinneranti : rotate the inner square 1 position anti-clockwise :

Eg. : If applied to the above grid , grid becomes :

1 2 3 4
12 16 13 5
11 15 14 6
10 9 8 7

The program should ask the usr to input the elements of the grid which will
be a single character(eg. A or 8 or c) .Then it should ask for a command
from the above 6 and perform the reqd. operations and show the grid until
the usr wishes to quit.

Sample Run :After inputting the grid :

Command : rxchg 1 2

(now show the grid after xchanging the rows 1 and 2)

Command : rotouteranti

(show the grid again after doing reqd. operation)

Command : quit

(exit from the program)

T1) Clear thy Logic

As u know,There are 7 operators in boolean algebra which will be represented
by the given symbols :

1)not : !
2)and  : *
2)nand : /
3)or : +
3)nor : -
4)xor : ^
4)xnor : &

The precedence of these operators is indicated by the nos. to their left : !
has the highest precedence, then * and /  both have the same precedence and
so on.
Given an expression with maximum of  4 variables which will be a,b,c,d along
with the operators and any no. of parentheses, draw the truth table for the
expression using the following rules :

1) The operator  in the innermost parentheses is given the highest priority.
2) If 2 operators are there in the same pair of parentheses then their
priority should be
    calculated from the above table and if they have the same priority (eg.
* and /) then
    precedence goes to the operator on the left hand side.
3)The individual truth-tables for all the operators are the same as those
applied in logic
   ckts. Eg.: 1+0=1; 1^1=0; 1*0=0; 0/1=1.

Input will be a character string containing any of the 4 variables a,b,c,d
along with the operators.No spaces will be included in the input.

Eg. :

a+(b*(c-a)^d)*c

Let's say the values of a,b,c,d are 1,0,1,0 respectively.

Expr = 1+(0*(1-1)^0)*1
        = 1+(0*0^0)*1
= 1+(0^0)*1
= 1+0*1
= 1+0
= 1.

Eg : INPUT

Enter the expression : a+(b^c)

OUTPUT

A b c Expr.
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 1
1 1 0 1
1 1 1 1


T2) Do Our Simulation(DOS)

Write a program to simulate the md, cd, rd features of a dos system .

The permitted commands are :

md <dir-name>
cd <dir-name>
rd <dir-name>
cd..
cd\
dir

When the program is run, display the dummy command prompt as the root
directory c:>.The program should be terminated when the exit command is
given.

Now let's see an example :

C:>md ieee
C:>cd ieee
C:\ieee>md olpc
C:\ieee>cd olpc
C:\ieee\olpc>cd\
C:>rd C:\ieee\olpc
C:>cd c:\ieee
C:\ieee>cd olpc
Directory doesn't exist!
C:\ieee>md members
C:\ieee>cd members
C:\ieee\members>rd c:\ieee
C:\ieee\members>can't delete the directory until all subdirectories are
deleted!
C:\ieee\members>cd..
C:\ieee>dir
members
C:\ieee>cd\
C:>exit



I)Solve it if u can!!!

Suppose that you have a water pot with a capacity of L liters and n water
bottles with capacities c1, c2, ., cn. Write a
program to select m bottles of water to fill
up the water pot, or answer there is no solution. The selected bottles have
to be arranged in increasing order. If you select a
bottle of water, the bottle has to be
completely poured in. Also, all bottles are full initially. If two solutions
have the same numbers of bottles, select the one that has
a bottle with the largest capacity.
For example, if {5, 8} and {6, 7} are two possible solutions to fill up a
water pot of capacity 13, then select {5, 8} as the
problem solution. If the largest volume in
two solutions is the same and there is more than one possible solution, you
have to select the one with fewer bottles. For
example, if {2, 3, 8} and {5, 8} are two
possible solutions to fill up a water pot with capacity 13, then you have to
select {5, 8} as the problem solution. Note that if you try to solve this
problem by a
brute-force method, the program execution time may exceed the run-time
limit.

[Input Format]

Ask for the values of n, L, c1, c2, .. ,cn.
Note that all capacities will be input as integer .

[Output Format]

Print the jug nos. (cn) reqd. to fill the pot along with their capacities.

[Sample Run]

Enter L,n :  12  6
Enter c1 : 3
Enter c2 : 4
Enter c3 : 7
Enter c4 : 8
Enter c5 : 1
Enter c6 : 5

The Jugs reqd. are :
C3 : 7 litres
C6 : 5 litres.