anuprao85
BAN USER- -1of 3 votes
AnswersA frog has to cross the river from one end to another end. river has stones in between randomly where frog can jump. frog can't jump into the river. problem is that will frog ever reach other end with following conditions?
- anuprao85 in United States for Office
1. frog allow to do same jump as previous jump. or
2. frog allow to jump 1 more as previous jump. or
3. frog allow to jump 1 less as previous jump.
consider river as Boolean Array. Stone is a element in array where value is true .| Report Duplicate | Flag | PURGE
Microsoft Software Developer Data Structures
frog should reach one point ( starting point ) to another point ( destination point ).
To reach destination frog requires to jump to stones only.
Frog jump shouldn't be random, but must fulfill either one condition out of 3 condition mentioned in a question.
e.g. If first jump is 3 , then next jump must be either 2(jump - 1) or 3(same jump) or 4( jump + 1 ) and so on. jump must be on stone not on water in river.
public class _26BaseToDecimal
{
char[] alpha = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
public void lettersToDecimal(string input, int baseN=26)
{
int decimalN = 0;
for (int i = 0; i < input.Length; i++)
{
// aasci value for 'a' is 97 so, a-a + 1=97-97 + 1= 1 , So a=>1, b-a+1=98-97+1=2, so b=>2 (mapping)
decimalN = decimalN * baseN + int.Parse((input[i] - 'a' + 1).ToString());
}
Console.WriteLine("For alphabate {0} decimal is {1}", input, decimalN);
}
}
//dynamic progrming
public void GetMaxSubSequenceSumDynamicprog()
{
//maxsum [i] = Max ( maxsum(i-1) + A[i], A[i])
int maxsum = 0;
//int prevsum;
for (int i = 0; i < elements.Length -1; i++)
{
//prevsum = maxsum;
maxsum += elements[i];
maxsum = Math.Max(maxsum, elements[i]);
}
}
class person
{
public int id;
public int[] knownPersonId;
public person(int id, int[] knownPersonId)
{
this.id = id;
this.knownPersonId = knownPersonId;
}
}
class FindCelebrity
{
public person findCelebrity(List<person> candidatesforCelebrity)
{
List<person> p = GetCelebrityCandidatePeople(candidatesforCelebrity);
if (p.Count == 1) return p[0];
else
return findCelebrity(p);
}
public List<person> GetCelebrityCandidatePeople(List<person> candidatesforCelebrity)
{
List<person> newcandidates = new List<person>();
for (int i = 0; i < candidatesforCelebrity.Count; i++)
{
for (int j = 0; j < candidatesforCelebrity.Count; j++)
{
if (IsKnow(candidatesforCelebrity[i], candidatesforCelebrity[j]))
{
//candidatesforCelebrity.Add(people[j]);
newcandidates.Add(candidatesforCelebrity[j]);
}
}
return newcandidates;
}
return newcandidates;
}
public Boolean IsKnow(person a, person b)
{
Boolean know= false;
for (int i = 0; i < a.knownPersonId.Length; i++)
{
if (a.knownPersonId[i] == b.id)
{
know = true;
return know;
//break;
}
}
if (!know)
{
return know;
}
return know;
}
public static void main()
{
List<person> persons= new List<person>();
persons.Add( new person(1, new int[] { 2,3,4 }));
persons.Add( new person(2, new int[] { 1,3,4 }));
persons.Add( new person(3, new int[] { 1,4 }));
persons.Add( new person(4, new int[] {}));
persons.Add( new person(5, new int[] { 2, 4 }));
FindCelebrity c = new FindCelebrity();
person p = c.findCelebrity(persons);
Console.Read();
}
}
yes correct.
- anuprao85 December 01, 2015