hackerearth-1

Upload: santosh-kumar-desai

Post on 12-Oct-2015

599 views

Category:

Documents


10 download

DESCRIPTION

hacker earth competition questions

TRANSCRIPT

Jungle RunMax. Score100You 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)5S P P P PT P T P PT P P P PP T E T TP T P T TSample Output(Plaintext Link)5Time Limit5 sec(s)(Time limit is for each input file.)Memory Limit256 MBSource Limit1024 K

Strategic Warehouse placementsMax. Score100A 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 formatN MS1 E1 (Start Pt and End Pt of a direct route)S2 E2S3 E3....SM EMEach route is bidirectionalNo combination of towns will be repeated.[Output]:Output should be in a file in the following formatWx - Minimum # of warehouses*Problem provided by JDA

Sample Input(Plaintext Link)10 71 22 42 53 68 69 710 7Sample Output(Plaintext Link)3Time Limit5 sec(s)(Time limit is for each input file.)Memory Limit256 MBSource Limit1024 KB

Smart travel agentMax. Score100Our 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 101 2 301 3 151 4 102 4 252 5 603 4 403 6 204 7 355 7 206 7 301 7 99Sample Output(Plaintext Link)1 2 4 75Time Limit5 sec(s)(Time limit is for each input file.)Memory Limit256 MBSource Limit1024 KB

Rotate, rotate again and rotate once moreMax. Score100Mr 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 areNstudents in his class. Lets mark the students from1,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 classOrder 1: C L R Kwhere C is character 'C', stands for clockwise,L is a number 1 EAST ]Input Format:First line of the input contains N, M separated by spaceN is the number of students in classM is the number of ordersNow M lines follow, each line contains one of the following three types of orderC L R Kor, A L R Kor, Q L ROutput Format:For every order of type 3, i.e "Q L R" , output the required number in a new lineConstraints:1 [ (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 3Time Limit1 sec(s)(Time limit is for each input file.)Memory Limit512 MBSource Limit1024 KB

String chainingMax. Score100Input will be a list of the N (