Home Answers Viewqa Java-Beginners Give me the source code for this problem

 
 


srilatha nagandla
Give me the source code for this problem
1 Answer(s)      8 months ago
Posted in : Java Beginners

Ram likes skiing a lot. That's not very surprising, since skiing is really great. The problem with skiing is one have to slide downwards to gain speed. Also when reached the bottom most point one has to wait for ski-lift to get to higher altitude.

Ram seeks your help to know the longest run possible with the given peaks. That altitude of different peaks is given by a grid of numbers. Look at this example:

7 2 3 4 5 36 37 38 34 6 33 44 46 40 7 24 43 42 41 8 35 32 47 30 9

One can ski down from one peak to a connected peak if and only if the height decreases. One peak is connected to another if it's at left, at right, above or below it. In the sample map, a possible ski path would be 36-33-24(start at 36, end at 24). Of course if one would ski 46-44-43-42-41-30-9....3-2, it would be a much longer run. In fact, it's the longest possible. There could be more than one longest ski path, but all Ram needs from you is to tell maximum number of peaks he could cover for a given map, in this case it is 14.

Input All input comes from input.txt file. The first line contains the number of test cases N. Each test case starts with a line containing the name (it's a single string), the number of rows R and the number of columns C. After that follow R lines with C numbers each, defining the heights. R and C won't be bigger than 100.

Output For each test case, print a line to output.txt containing the name of the area, a colon, a space and the length of the longest run (maximum points covered) one can slide down in that area.

Sample Input 2 Manali 10 5 56 14 51 58 88 26 94 24 39 41 24 16 8 51 51 76 72 77 43 10 38 50 59 84 81 5 23 37 71 77 96 10 93 53 82 94 15 96 69 9 74 0 62 38 96 37 54 55 82 38 Narkanda 5 5
1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9

Sample Output Manali: 7 Narkanda: 25

View Answers

January 3, 2013 at 3:06 PM


public class SkiPath { private static Integer[][] peaks = {{7,2,3,4,5}, {36,37,38,34,6}, {33,44,46,40,7}, {24,43,42,41,8}, {35,32,47,30,9}};

private static Integer[][] lRun = {{1,1,1,1,1}, {1,1,1,1,1}, {1,1,1,1,1}, {1,1,1,1,1}, {1,1,1,1,1};

public static int calLongestRun(int i,int j){ int useLeft = -1; int useRight = -1; int useAbove = -1; int useBelow = -1;

if(isAllowed(i,j-1,i,j)) useLeft = 1 + calLongestRun(i,j-1); if(isAllowed(i,j+1,i,j)) useRight = 1 + calLongestRun(i,j+1); if(isAllowed(i-1,j,i,j)) useAbove = 1 + calLongestRun(i-1,j); if(isAllowed(i+1,j,i,j)) useBelow = 1 + calLongestRun(i+1,j); return max(useLeft,useRight,useAbove,useBelow); }

public static int max(int lr,int rr,int ar,int br){ int m=1; if(lr > m) m = lr; if(rr > m) m = rr; if(ar > m) m = ar; if(br > m) m = br; return m; }

public static boolean isAllowed(int x1,int y1,int x,int y){ boolean ret = false; if(x1 >= 0 && y1 >= 0 && x1 < 5 && y1 < 5){ if(peaks[x1][y1] < peaks[x][y]) ret = true; } return ret; }

public static void main(String[] s){ for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ lRun[i][j] = calLongestRun(i,j); } }

int m = 1;

for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ if(m < lRun[i][j]) m = lRun[i][j]; } }

System.out.println("Longest Run is : "+m); }

}

Output: 14









Related Pages:
Give me the source code for this problem
Give me the source code for this problem  Ram likes skiing a lot. That's not very surprising, since skiing is really great. The problem with skiing is one have to slide downwards to gain speed. Also when reached the bottom most
give me source code of webpage creation using html
give me source code of webpage creation using html  how to create a webpage using html
Please give me the code for the below problem - Java Interview Questions
Please give me the code for the below problem  PROBLEM : SALES TAXES Basic sales tax is applicable at a rate of 10% on all goods, except books... Vidya  Hi Friend, Try the following code: import java.util.
source code
source code  hellow!i am developing a web portal in which i need to set dialy,weekly,monthly reminers so please give me source code in jsp
Plz give me code for this question
Plz give me code for this question  Program to find depth of the file in a directory and list all files those are having more number of parent directories
hibernate code problem - Hibernate
/selectclause.shtml If you have any problem this send me detail and source code...hibernate code problem  suppose i want to fetch a row from the table... it plz give the complete code  Hi friend, I am sending you a link
verify the code and give me the code with out errors
verify the code and give me the code with out errors   import... clear the errors and give me correct tutorial for my knowledge improving.pls anyone help me. E:\>java add java.lang.NullPointerException at add
Problem with Java Source Code - Java Beginners
Problem with Java Source Code  Dear Sir I have Following Source Code ,But There is Problem with classes, plz Help Me. package mes.gui; import javax.swing.JOptionPane.*; import java.sql.*; import javax.swing.*; import
please help me to give code - Java Beginners
please help me to give code  Write a function with a signature cheerlead(word) that prints a typical cheer as follows. The word robot: Gimme an R Gimme an O Gimme a B Gimme an O Gimme a T What did you give me? ROBOT
give me a grid example in php
give me a grid example in php  give me easy code example of grid in php like mysql editor
source code - JDBC
source code  give me a source code to connect from java to mysql that can run on eclipsed i am using mysql-essential-5.0.41-win32_1. also give procedure how can i connect from eclipsed to mysql-essential-5.0.41-win32_1. thanks
please help me to give code - Java Beginners
please help me to give code  Write a function, sliding(word, num)that behaves as follows. It should print out each slice of the original word having length num, aligned vertically as shown below. A call to sliding(examples, 4
please help me to give code - Java Beginners
please help me to give code  Write a program that prints an n-level stair case made of text. The user should choose the text character and the number of stairs in the stair case * ** *** ****   Hi friend
please help me to give code - Java Beginners
please help me to give code  Write a program that uses loops to generate an n x n times table. The program should get n from the user. As a model here is a 4 x4 version: | 1 2 3 4
please help me to give code - Java Beginners
please help me to give code  Write a program that reads a file named famous.txt and prints out the line with the longest length. In the case of a tie, you may print out only one of them. For example in the file: Alan Turing
reg : the want of source code
) Available Seats and etc. plz Give Me Full Source code with Database...reg : the want of source code  Front End -JAVA Back End - MS Access Hello Sir, I want College Student Admission Project in Java with Source code
please help me to overcome this problem
please help me to overcome this problem  how to make it easy to write java code. can u please give me suggestions
give information or website address
give information or website address  hi i want u r help .... i m finding code for constructing graph in java but during execting them i have problem bec of packages... has i proceed i came to know
how to send email please give me details with code in jsp,servlet
how to send email please give me details with code in jsp,servlet  how to send email please give me details with code in jsp,servlet
Pleae help me to give logic and code for this program - Java Beginners
Pleae help me to give logic and code for this program  Write a function that given the string ?original? create a new string ?dramatic? that has two consecutive copies of each letter from the original string. For example
code problem - Java Beginners
code problem  1)what is accurate use of access specifiers (plz give me all uses in options)..? 2)In folllowing options which can be used by the inner class....? a)private instance variables b)public instance variables c
code problem - Java Beginners
code problem  1)what is accurate use of access specifiers (plz give me all uses in options)..? 2)In folllowing options which can be used by the inner class....? a)private instance variables b)public instance variables c
please give me a java program for the following question
please give me a java program for the following question  Write...; In the previous code, we forget to add an icon to button. So we are sending the updated code. import java.awt.*; import javax.swing.*; import
jsp code problem - JSP-Servlet
have a problem with open the next form. plz, help me. thanks,  Hi friend, Please give me detail and send me error code page. Please...jsp code problem  Hi, I have employee details form in jsp. After
Servlet problem
connectivity code it works but problem is with servlet page. My servlet code... problem from last three month and now i hope rose india developers will definitely help me. I built a web application using jsp, servlets . My web application
plz give me answer
plz give me answer  Discuss & Give brief description about string class methods   Java string methods
plz give me answer
plz give me answer   description about string class methods   Java string methods
plz give me answer
plz give me answer   description about string class methods   Java string methods
plz give me answer
plz give me answer   description about string class methods   Java string methods
source code in jsp
source code in jsp  sir...i need the code for inserting images into the product catalog page and code to display it to the customers when they login to site..pls help me
Open Source Jobs
on the West coast to get a great job and still give back to the open source community... the source code is available to the general public for use and/or modification from its original design free of charge. Open source code is typically created
Please give me the answer.
"int a=08 or 09" its giving compile time error why   "int a=08 or 09" its giving compile time error why ? can any one give me the answer of this please
pls give me answer ae soon as possible - Ajax
pls give me answer ae soon as possible  i m writing code of ajax technology ...but it is not working pls check it n give me response quickly... give me quick response!!! thanks & regards shashank gupta
GIVE ME A ANSWER
GIVE ME A ANSWER  Discuss the Number Class in the java.lang package   Number class is an abstract class extended by all classes that represent numeric primitive types such as Byte, Short, Integer, Long, Float
Please give me coding for this..
Please give me coding for this..  Write an application that inputs one number consisting of five digits from the user.separates the number ibto its individual digits and prints the digits separated from one another by three
source code - Java Beginners
source code  Hi...i`m new in java..please help me to write program that stores the following numbers in an array named price: 9.92, 6.32, 12,63... message dialog box.  Hi Friend, Try the following code: import
StringIndexOutOfBound error !!! plz give me the reason for this error ,plz.........
StringIndexOutOfBound error !!! plz give me the reason for this error ,plz.........  import java.util.Scanner; class Even { static int getEven(int... at java.lang.String.charAt(Unknown Source) at Even.main(Even.java:27) <<< Process
XML load problem - XML
XML load problem  I have load the xml document in javascript.getting error like ActiveXObject is undefined.Can you help me?  Hi friend, Plz give full details with source code to solve the problem and visit
plz give me answer plz
plz give me answer plz  writw a programme to find rank from an array using doubledimmensionalarray
Source Code for Search Engine Project in java - Java Beginners
Source Code for Search Engine Project in java  Hello Sir ,I want Java Project for Search Engine(like google),How I can Make it,Plz Give Me Complete Source Code Of Search Engine Project in Java.  Hi Friend, Please
attendance management system source code
attendance management system source code  sir i want full ateendance management project please send me source code i am asking so many members... answer so please send code it's very urgent
Open Source Jobs
on the West coast to get a great job and still give back to the open source community... the source code is available to the general public for use and/or modification from its original design free of charge. Open source code is typically created
java source code - Java Beginners
java source code  I have written a source code for recording invoices. I wish it to be evaluated. Could somebody help me with it? Moreover, I do not know the method to attach the JAR for evaluation. My email
code problem:ajax - Ajax
code problem:ajax  Hi,I am using ajax to populate a select box.for this I am writing out.write("ONE"); like that.it runs fine in firefox.bt not in IE.Can anyone help me out this... thanks
Source Code cls - Java Beginners
Source Code cls   Dear RoseIndia Team, Thanks for your prompt reply to my question about alternate to cls of dos on command line source code. I... a oneliner (i.e cls) this would give us the same result. No need of compiling/running
give the code for servlets session
give the code for servlets session  k give the code of total sample examples of servlet session
attendance management project source code
attendance management project source code  sir i want full ateendance management project please send me source code i am asking so many members... answer so please send code it's very urgent
attendance management project source code
attendance management project source code  sir i want full ateendance management project please send me source code i am asking so many members... answer so please send code it's very urgent
static code problem - Java Interview Questions
static code problem  do we overload or override static methods if possible please give me the example  Hi Friend, Yes, you can overload and override static methods but only with static methods. For ex. public
code problem - Java Beginners
code problem  Dear sir, my problem is that I've a string value if this String value has "quit" then output should be "bye". i want to make... help me. thnx