Re: [algogeeks] size of array

2013-01-29 Thread naveen bansal
If the array was declared as int array[100];

then sizeof operator will give you the size of that array. then length can
found as
length = sizeof(array)/sizeof(int);
if the array was declared dynamic then you can not find the length of that
array.

Naveen

On Mon, Jan 28, 2013 at 3:44 PM, Anil Sharma wrote:

> How to calculate the size/lenght of an int array which is passed as an
> ONLY argument to a function???
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] size of array

2013-01-29 Thread Nishant Pandey
i think this is not possible as you are passing only base address of the
int array to it , there is not information about the owner .

On Mon, Jan 28, 2013 at 3:44 PM, Anil Sharma wrote:

> How to calculate the size/lenght of an int array which is passed as an
> ONLY argument to a function???
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: DP equation for interval problem

2013-01-29 Thread Nikhil Karnwal
no ...when u figure out those m matches just sort them ..now let k=[0,m]
if currently u are assuming that kth match is already sliced then all
before that k matches are already sliced.and this u can do by moving
incrementally from 0 to mth matches.

On Mon, Jan 28, 2013 at 1:43 PM, foram lakhani wrote:

> by match u mean that number of fruits that overlap with i th fruit but are
> not sliced before time i.
> which means we have to consider 2^m cases where m is the maximum number of
> fruits that overlap with ith fruit.
> And this we have to do for each fruit.
>
> On Mon, Jan 28, 2013 at 12:54 AM, Nikhil Karnwal wrote:
>
>> Actually dp[i] represent the state in which u make a slice at appearing
>> time of i th fruits.and match represent the overlapping fruits
>> with i.
>> so
>> for each i dp[i]=max(dp[i],dp[j]+match);
>> for all j=[0,i] and match =overlapped fruits with i which are not sliced
>> until the cut of j.
>> Hope this will help.
>> Thanks
>>
>> On Thu, Jan 24, 2013 at 10:18 PM, foram lakhani 
>> wrote:
>>
>>> Thanx for the reply but I didnt get you. What does dp[i] represent ?
>>>
>>>
>>>  On Thu, Jan 24, 2013 at 9:50 PM, sunny  wrote:
>>>
 take a structure or pair of start time and finish time and then sort
 the the structure you know the comparator function  the for each for each
 dp[i] select j belongs to  (0,i) and then count the overlap value


 if(j==0)
 dp[i]=max(dp[i],match);
 else
  dp[i]=max(dp[i],dp[j-1]+match);


 with this recursive relation my code got accepted in .24 sec others
 approach you mentioned may lead to the TLE

 On Thursday, January 24, 2013 1:35:38 PM UTC+5:30, emmy wrote:
>
> please help me with the following problem:
>  
> http://www.spoj.com/problems/**JUICE/
>
> bit mask will require very large memory.
> If I sort the intervals in decreasing order of their start time.. I
> still cant make it to a dp
> If I sort the intervals in decreasing order of their finish times I am
> still not getting a recurrence for dp that is valid
> If I convert this to an interval graph, I have to find the maximum
> number of vertices that can be included in some clique of size >=3. But
> this also seems like a brute force approach.
>
> Which approach to try?? please help!!
>
>  --



>>>
>>>  --
>>>
>>>
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] size of array

2013-01-29 Thread Anil Sharma
How to calculate the size/lenght of an int array which is passed as an ONLY
argument to a function???

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Puzzle.. How to solve??

2013-01-29 Thread Anmol Dhar
Answer:
1)-> (4)
2)--> (2)
3)---> (a)
4)> doubt, for which team match fees you are asking?
5)> (b)
Correct me if i'm wrong..please don't reply with  answers if i'm
incorrect... wanna give one more shot! ;)

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks]

2013-01-29 Thread shady
Yes I agree to it, it won't be random... but suppose I don't want a case
when all elements are at their own position because that case means
that they are not shuffled. Perhaps we can run the algorithm again, since
the probability of same event occurring two times in a row will be very
less.

On Tue, Jan 29, 2013 at 12:13 AM, Carl Barton wrote:

> Because then it's not a random shuffle? If you randomly shuffle something
> the order you currently have should be just as likely as any other
>
>
> On 28 January 2013 12:29, shady  wrote:
>
>> Why do we use Fisher Yates 
>> algorithm
>>  when
>> in the worst case there is no shuffle at all ?
>> we can modify it by generating random number not inclusive of the element
>> that we are about to swap
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Puzzle.. How to solve??

2013-01-29 Thread varun pahwa
Hi,
Look at team Team7. F2,F9,F12,F14,F15.
=> F12 -> Chelsa.
C -> 7,12
L -> 2,9
and 14,15 not from liverpool.
Now, look at Team 6.
So,
C -> 7,12
L -> 3,6,2,9
U -> 15 , 1 (From Team 1)
Team 2 -> 11 & 13 not from liverpool.
Team 3 -> 11 & 5 not from liverpool
Team 5 => 11 from C
So,
C -> 7,12,11,10 (From Team 4),14 (From Team 7)
L -> 3,6,2,9,4(From Team 5),16 (From Team 5), 8 (From Team 8)
U -> 15 , 1 , 5 (From Team 3), 13 (From Team 8)

Rewriting it.
L -> 2,3,4,6,8,9,16
C -> 7,10,11,12,14
U -> 1,5,13,15


Now, all the questions can be answered.
Hope I'm cleared.

Thanks & Regards,
Varun





On Tue, Jan 29, 2013 at 12:25 AM, nikhil rao  wrote:

> Dream teams are formed by television viewers by selecting five players
> from the sixteen players namely
> F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,F14,F15 and F16.The players
> belong to exactly one of the three teams namely Chelsea,Liverpool and
> United.Every Dream Team must have two players each from Chelsea and
> Liverpool and one player from united.Following information is provided
>
> a)F12 is not from United
> b)F7 is from Chesla.
> c)F2 and F9 are from liverpool
> d)the 'match fee' of each player belonging to chesla ,liverpool, and
> united is Euro 800.Euro775 and euro 725 match played respectively.
>
> 8 such dearm teams were formed are mentioned below...
> team1=F3,F9,F7,F1,F12
> Team2=F12,F11,F13,F6,F9
> Team3=F6,F3,F5,F11,F7
> Team4=F2,F10,F7,F6,F1
> Team5=F1,F4,F16,F11,F10
> Team6=F6,F3,F7,F15,F12
> Team7=F2,F9,F12,F14,F15
> Team8=F4,F8,F13,F11,F10
>
>Q1)in dream team 6 name the united player?
> 1)F3 2)F6 3)F12 4)F15
>
> Q2)how many players belong to Chesla from the given sixteen   players?
> 1)4 2)5 3) 6 4)7
>
>   Q3)In team 8 who are from liverpool?
> a)F4,F8
> b)F10,F11
> c)F11,F13
> d)F4,F11
>
>  Q4)what is the total fees per match (in Euros) for team ?
> 1)3875
> 2)3825
> 3)3800
> 4)none of these
>
>   Q5)which of the following combinations have only Liverpool players?
> a)F13,F3
> b)F3,F16
> c)F16,F14
> d)F14,F2
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Varun
Product Engineer,
Vizury

People who fail to plan are those who plan to fail.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: Generating mazes

2013-01-29 Thread Piyush Grover
@Don can you give the logic of your rnd() function?

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Re: Generating mazes

2013-01-29 Thread Don
A few years ago one of my winning entries in the International
Obfuscated C Code Contest generated and let the user solve a 3D maze.
The program below is not obfuscated, and it only generates a 2D maze,
but it illustrates the principle.
The idea is to start with a solid area of wall and then tunnel out the
passageways. From a given point, it tries in a random order to tunnel
in each of the four directions. If it succeeds, it digs a tunnel to
that neighboring location and stores the direction it used to get to
that location, and then continues to tunnel from that new location.
When it gets to a point where it can't tunnel in any direction, it
uses the direction to back out to its previous location. It is not
recursive, like many maze generating programs. It stores it's stack
inside of the maze. The resulting maze could be used to generate a
bitmap image. In this case I just output a text representation.

Don

===

#include 
#include 

unsigned int rnd()
{
   static unsigned int x = time(0);
   x = 63663*(x&65535) + (x>>16);
   return x&65535;
}

int main()
{
   // Size should be odd
   const int size = 199;
   char m[size][size];
   int i,j,d,x,y,tmp,order[4] = {0,1,2,3};
   int dir[4][2] = {{1,0}, {0,1}, {-1,0}, {0,-1}};
   enum markers { passage=4, start=5, wall=6 };

   // Fill area solid
   for(i = 0; i < size; ++i)
  for(j = 0; j < size; ++j)
 m[i][j] = wall;
   for(i = 0; i < size; ++i)
  m[i][0] = m[0][i] = m[i][size-1] = m[size-1][i] = passage;

   // Select starting location
   i = j = (size/2) & 0xfffe;
   m[i][j] = start;

   // Dig tunnels
   while(1)
   {
  // Permute directions
  for(x = 1; x < 4; ++x)
  {
 y = rnd() % (x+1);
 tmp = order[x];
 order[x] = order[y];
 order[y] = tmp;
  }

  // Try directions in selected order
  for(d = 0; d < 4; ++d)
  {
 x = dir[order[d]][0];
 y = dir[order[d]][1];
 if (m[i+2*x][j+2*y] == wall)
 {
m[i+x][j+y] = passage;
i += 2*x;
j += 2*y;
m[i][j] = order[d];
break;
 }
  }

  // Nowhere to go. Back out.
  if (d == passage)
  {
 x = m[i][j];
 m[i][j] = passage;
 if (x == start) break;  // Done
 i -= 2*dir[x][0];
 j -= 2*dir[x][1];
  }
   }

   // Start and end
   m[2][1] = m[size-3][size-2] = passage;

   // Print result
   for(i = 0; i < size; ++i)
   {
  for(j = 0; j < size; ++j)
 printf("%c", (m[i][j] == wall) ? '#' : ' ');
  printf("\n");
   }

   return 0;
}

On Jan 29, 6:51 pm, Dave  wrote:
> Does anyone have any ideas about how to generate mazes? I'd like an
> algorithm that can make many different mazes, maybe using a random number
> generator. Each maze should be guaranteed to have one and only one solution.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Re: Generating mazes

2013-01-29 Thread Don
A few years ago one of my winning entries in the International
Obfuscated C Code Contest generated and let the user solve a 3D maze.
The program below is not obfuscated, and it only generates a 2D maze,
but it illustrates the principle.
The idea is to start with a solid area of wall and then tunnel out the
passageways. From a given point, it tries in a random order to tunnel
in each of the four directions. If it succeeds, it digs a tunnel to
that neighboring location and stores the direction it used to get to
that location, and then continues to tunnel from that new location.
When it gets to a point where it can't tunnel in any direction, it
uses the direction to back out to its previous location. It is not
recursive, like many maze generating programs. It stores it's stack
inside of the maze. The resulting maze could be used to generate a
bitmap image. In this case I just output a text representation.

Don




#include 
#include 

unsigned int rnd()
{
   static unsigned int x = time(0);
   x = 63663*(x&65535) + (x>>16);
   return x&65535;
}

int main()
{
   // Size should be odd
   const int size = 199;
   char m[size][size];
   int i,j,d,x,y,tmp,order[4] = {0,1,2,3};
   int dir[4][2] = {{1,0}, {0,1}, {-1,0}, {0,-1}};
   enum markers { passage=4, start=5, wall=6 };

   // Fill area solid
   for(i = 0; i < size; ++i)
  for(j = 0; j < size; ++j)
 m[i][j] = wall;
   for(i = 0; i < size; ++i)
  m[i][0] = m[0][i] = m[i][size-1] = m[size-1][i] = passage;

   // Select starting location
   i = j = (size/2) & 0xfffe;
   m[i][j] = start;

   // Dig tunnels
   while(1)
   {
  // Permute directions
  for(x = 1; x < 4; ++x)
  {
 y = rnd() % (x+1);
 tmp = order[x];
 order[x] = order[y];
 order[y] = tmp;
  }

  // Try directions in selected order
  for(d = 0; d < 4; ++d)
  {
 x = dir[order[d]][0]];
 y = dir[order[d]][1]];
 if (m[i+2*x][j+2*y] == wall)
 {
m[i+x][j+y] = passage;
i += 2*x;
j += 2*y;
m[i][j] = order[d];
break;
 }
  }

  // Nowhere to go. Back out.
  if (d == passage)
  {
 x = m[i][j];
 m[i][j] = passage;
 if (x == start) break;  // Done
 i -= 2*dir[x][0];
 j -= 2*dir[x][1];
  }
   }

   // Start and end
   m[2][1] = m[size-3][size-2] = passage;

   // Print result
   for(i = 0; i < size; ++i)
   {
  for(j = 0; j < size; ++j)
 printf("%c", (m[i][j] == wall) ? '#' : ' ');
  printf("\n");
   }

   return 0;
}

On Jan 29, 6:51 pm, Dave  wrote:
> Does anyone have any ideas about how to generate mazes? I'd like an
> algorithm that can make many different mazes, maybe using a random number
> generator. Each maze should be guaranteed to have one and only one solution.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[algogeeks] Generating mazes

2013-01-29 Thread Dave
Does anyone have any ideas about how to generate mazes? I'd like an 
algorithm that can make many different mazes, maybe using a random number 
generator. Each maze should be guaranteed to have one and only one solution.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.