Sei sulla pagina 1di 7

Jungle Run

Max. Score100
You are lost in a dense jungle and it is getting dark. There is at least one path that leads you to the
city on the other side but you cannot see anything until you are right in front of it as the trees and
bushes obscure the path.
Devise an algorithm that is guaranteed to find the way out. Your goal is to go out of the jungle as fast
as you can before it gets dark.
[Input]:
Input start with a number N and then the matrix of size N x N filled with S, E, T, and P which is our
map. Map contains a single S representing the start point, and single E representing the end point
and P representing the path and T representing the Tree.
[Output]:
output single integer i.e. minimum number of moves from S to E.
Assumptions:
You can assume that the maps would be in square form and can be up to a maximum size of 30X30.
You can move in four directions North East West South.
You can move in any direction when you find P but cannot move to a point where a T is present.
*Problem provided by JDA

Sample Input (Plaintext Link)
5
S P P P P
T P T P P
T P P P P
P T E T T
P T P T T
Sample Output (Plaintext Link)
5
Time Limit5 sec(s) (Time limit is for each input file.)
Memory Limit256 MB
Source Limit1024 K

Strategic Warehouse placements
Max. Score100
A big international retailer is setting up shop in India and plans to open stores in N towns (3 N
1000), denoted by 1, 2, . . . , N. There are direct routes connecting M pairs among these towns. The
company decides to build warehouses to ensure that for any town X, there will be a warehouse
located either in X or in an immediately neighboring town of X.
Write a program to find the minimum number of warehouses the company has to build.
[Input]:
Input will be given in the following format
N M
S1 E1 (Start Pt and End Pt of a direct route)
S2 E2
S3 E3
....
SM EM
Each route is bidirectional
No combination of towns will be repeated.
[Output]:
Output should be in a file in the following format
Wx - Minimum # of warehouses
*Problem provided by JDA

Sample Input (Plaintext Link)
10 7
1 2
2 4
2 5
3 6
8 6
9 7
10 7
Sample Output (Plaintext Link)
3
Time Limit5 sec(s) (Time limit is for each input file.)
Memory Limit256 MB
Source Limit1024 KB

Smart travel agent
Max. Score100
Our smart travel agent, Mr. X's current assignment is to show a group of tourists a distant city. As in
all countries, certain pairs of cities are connected by two-way roads. Each pair of neighboring cities
has a bus service that runs only between those two cities and uses the road that directly connects
them. Each bus service has a particular limit on the maximum number of passengers it can carry. Mr.
X has a map showing the cities and the roads connecting them, as well as the service limit for each
bus service.
It is not always possible for him to take all tourists to the destination city in a single trip. For example,
consider the following road map of seven cities, where the edges represent roads and the number
written on each edge indicates the passenger limit of the associated bus service.
In the diagram below, It will take at least five trips for Mr. X. to take 99 tourists from city 1 to city 7,
since he has to ride the bus with each group. The best route to take is 1 - 2 - 4 - 7.

Problem:
What is the best way for Mr. X to take all tourists to the destination city in the minimum number of
trips?
[Input]:
The first line will contain two integers: N (N 100) and R, representing the number of cities and the
number of road segments, respectively. Each of the next R lines will contain three integers (C1, C2,
and P) where C1 and C2 are the city numbers and P (P > 1) is the maximum number of passengers
that can be carried by the bus service between the two cities. City numbers are positive integers
ranging from 1 to N. The (R+1)th line will contain three integers (S, D, and T) representing,
respectively, the starting city, the destination city, and the number of tourists to be guided.
[Output]:
The output should contain 2 lines - the first line giving the route taken and the second line giving the
minimum number of trips
[Note]: If multiple solutions exist . Print lexicographically-smallest path .
Agent is also travelling in the same path so he has to be counted while travelling in that path for each
trip.
*Problem provided by JDA

Sample Input (Plaintext Link)
7 10
1 2 30
1 3 15
1 4 10
2 4 25
2 5 60
3 4 40
3 6 20
4 7 35
5 7 20
6 7 30
1 7 99
Sample Output (Plaintext Link)
1 2 4 7
5
Time Limit5 sec(s) (Time limit is for each input file.)
Memory Limit256 MB
Source Limit1024 KB

Rotate, rotate again and rotate once more
Max. Score100
Mr Lavit is teacher for physical education at a school. Today he is in bad mood, so he is taking it out
on the students of his class.
There are N students in his class. Lets mark the students from 1,2,.. upto N. They are standing in a
line.Initially, all the students are facing towards EAST.
Now he makes them sweat in sun.
He gives 3 types of orders to his class
Order 1: C L R K
where C is character 'C', stands for clockwise,
L is a number 1 <= L <= N,
R is a number L <= R <= N,
K is a number denoting number of steps to rotate.
This type of order means students in positions [L,R] has to rotate K steps clockwise.
Order 2: A L R K
where A is character 'A', stands for anti-clockwise,
L, R, and K are the same as in previous order.
This type of order means students in positions [L,R] has to rotate K steps anti-clockwise.
Order 3: Q L R
where Q is character 'Q', stands for query
L is a number 1 <= L <= N,
R is a number L <= R <= N,
This type of order is a query where he asks his class
the maximum number of students facing in a same direction in [L,R] positions.
If number of students facing in two, or more directions are maximum and equal, output this maximum
value.
If students answer wrong or answers very late then he may not let them go easily, so they have asked
for your help. Answer these queries on their behalf.
Rotation Explanation:
Suppose a student is facing EAST
Now if he is ordered to rotate 1 step clockwise then he would turn towards SOUTH,
so now he will be facing SOUTH
He is facing SOUTH, now if he is ordered to rotate 2 step clockwise, then he would turn WEST, then
to NORTH.
so now he will be facing NORTH
He is facing NORTH, now if he is ordered to rotate 5 steps anti-clockwise,
then he would turn (1) WEST, (2) SOUTH, (3) EAST, (4) NORTH , then (5) WEST so now he would
be facing WEST.
Clockwise direction [ EAST-->SOUTH-->WEST-->NORTH-->EAST ]
Anti-Clockwise direction [ EAST-->NORTH-->WEST-->SOUTH-->EAST ]
Input Format:
First line of the input contains N, M separated by space
N is the number of students in class
M is the number of orders
Now M lines follow, each line contains one of the following three types of order
C L R K
or, A L R K
or, Q L R
Output Format:
For every order of type 3, i.e "Q L R" , output the required number in a new line
Constraints:
1 <= N <= 10
6

1 <= M <= 2x10
4

1 <= L = N
L <= R <= N
1 <= K <= 10
9


Sample Input (Plaintext Link)
10 10
C 1 5 3
Q 2 6
A 3 7 6
Q 3 8
C 4 8 9
Q 5 10
A 2 8 1
Q 1 10
C 6 10 2
Q 7 10
Sample Output (Plaintext Link)
4
3
2
4
3
Explanation
Initially [ (1)E, (2)E, (3)E, (4)E, (5)E, (6)E, (7)E, (8)E, (9)E, 10(E) ]
C 1 5 3 --> [ (1)N, (2)N, (3)N, (4)N, (5)N, (6)E, (7)E, (8)E, (9)E, 10(E) ]
Q 2 6 --> 1 facing EAST, 0 facing SOUTH, 0 facing WEST, 4 facing NORTH, so output maximum i.e 4
A 3 7 6 --> [ (1)N, (2)N, (3)S, (4)S, (5)S, (6)W, (7)W, (8)E, (9)E, 10(E) ]
Q 3 8 --> 1 facing EAST, 3 facing SOUTH, 2 facing WEST, 0 facing NORTH, so output maximum i.e 3
C 4 8 9 --> [ (1)N, (2)N, (3)S, (4)W, (5)W, (6)N, (7)N, (8)S, (9)E, 10(E) ]
Q 5 10 --> 2 facing EAST, 1 facing SOUTH, 1 facing WEST, 2 facing NORTH, so output maximum i.e
2
A 2 8 1 --> [ (1)N, (2)W, (3)E, (4)S, (5)S, (6)W, (7)W, (8)E, (9)E, 10(E) ]
Q 1 10 --> 4 facing EAST, 2 facing SOUTH, 3 facing WEST, 1 facing NORTH, so output maximum i.e
4
C 6 10 2--> [ (1)N, (2)W, (3)E, (4)S, (5)S, (6)E, (7)E, (8)W, (9)W, 10(W) ]
Q 7 10 --> 1 facing EAST, 0 facing SOUTH, 3 facing WEST, 0 facing NORTH, so output maximum i.e
3
Time Limit1 sec(s) (Time limit is for each input file.)
Memory Limit512 MB
Source Limit1024 KB

String chaining
Max. Score100
Input will be a list of the N (<=11000) words from which you need to generate a chain of words
following these rules and guidelines:
In the word chain, for any two consecutive words #A, #B - first letter of word #B and last letter of
word #A must be same.
VAMSHI, IYAZ - Valid, Vamshi ends with letter I, IYAZ starts with I.
VAMSHI , RONALD invalid as the last letter of VAMSHI and first letter of RONALD does not
match, cannot be consecutive words.
No word has to be repeated twice in the output sequence.
- VINOD, DEV, VINOD words can be chained but sequence is invalid as
VINOD is repeated.
You are allowed to use given word from the list.
You are assured that the given input is will have all the words in upper case.
You are assured that given list of words are unique.
Scoring will be relative. In case of tie, lower runtime solution is considered.
Input Format:
N Number of the words in Dictionary
N lines with a word in each line
Output:
Print the sequence with a word in each line.
*Problem provided by JDA

Sample Input (Plaintext Link)
10
VINOD
ITAZ
DEV
VARUN
NAVNEET
NAZAR
RAVISH
HITESH
RAVI
VAMSHI
Sample Output (Plaintext Link)
VINOD
DEV
VARUN
NAZAR
RAVI
Explanation
Here Output 1 have small chain with 5 strings, so score will be 5
Time Limit3 sec(s) (Time limit is for each input file.)
Memory Limit256 MB
Source Limit1024 KB

Potrebbero piacerti anche