Re: [algogeeks] SPOJ problem : CANDY III

2012-06-21 Thread romil bansal
Initialize sum as zero for all test cases ie inside 1st for loop.
On Jun 21, 2012 5:22 PM, Mayank Singh singh13490may...@gmail.com wrote:

 here is my code :

 #includestdio.h
 #includestdlib.h

 int main()
 {
 long long cand,sum;
 int T,N,i,j,*temp;
 scanf(%d,T);
 temp= (int*)calloc(T, sizeof( int));
 sum = 0;
 for(i=0;iT;i++)
 {
 scanf(%d,N);
 for(j=0;jN;j++)
 {
 scanf(%lld,cand);
 sum = (sum+cand)%N;
 }
 if(sum == 0)
 temp[i]=1;
 else
 temp[i]=0;
 }
 for(i=0;iT;i++)
 {
 if(temp[i]==1)
 printf(YES\n);
 else
 printf(NO\n);
 }
 return 0;
 }

 it is giving WA in spoj. i am unable to find what is wrong with it..plz
 help me.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Microsoft question

2012-06-21 Thread romil bansal
Can't we use k iterations of bubble sort ?
On Jun 18, 2012 2:11 PM, Ramindar Singh ramin...@gmail.com wrote:

 We can use Median of medians


 http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general_selection_algorithm_-_Median_of_Medians_algorithm


 On Sunday, 17 June 2012 08:13:18 UTC+5:30, Prem Nagarajan wrote:

 Give an array of unsorted elements, find the kth smallest element in the
 array.

 The expected time complexity is O(n) and no extra memory space should be
 used.

 Quickselect algorithm can be used to obtain the solution. Can anyone
 explain how quickselect works?

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/4lQsacmUPYUJ.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: DE Shaw Q

2011-06-15 Thread romil bansal
i think it can be done by counting the no of starting heaps with 1 coins in
it before any heap with coin1 in it. if all the heaps have only one coin
that player1 win if heap%2==1
if there is any heap with 1 then player1 win if (starting heap with 1 coin
in them)%2==0.
eg
player 1 win in case 1 of 1,1,1 or 1,1,3

On Wed, Jun 15, 2011 at 7:10 PM, L prnk.bhatna...@gmail.com wrote:

 The ordering of coins matter for this problem.
 For ex.
 1 2 and 2 1 have different results.
 So, i don't think that there would be a direct formula for this
 problem.
 We will have to traverse all the heaps of coins determining whether
 the current player is in winning or losing position.

 On Jun 15, 6:24 pm, sunny agrawal sunny816.i...@gmail.com wrote:
  @Nitish
  n=2
  heap 1 = 2
  heap 2 = 3
  Xor = 1
  still player one can win :)
 
  On Wed, Jun 15, 2011 at 6:49 PM, sunny agrawal sunny816.i...@gmail.com
 wrote:
 
 
 
 
 
 
 
 
 
   @immanuel
   ohh,   i read the Question wrong. :(
   i was thinking player1 is starting from least numbered heap and player
 2
   from highest no heap
 
   On Wed, Jun 15, 2011 at 6:36 PM, immanuel kingston 
   kingston.imman...@gmail.com wrote:
 
   Player 1 will take 1 coin from heap 1
   Player 2 has to take the other coin from heap1.
 
   Player 1 will take both the coins in heap 2.
 
   Thanks,
   Immanuel
 
   On Wed, Jun 15, 2011 at 6:33 PM, sunny agrawal 
 sunny816.i...@gmail.comwrote:
 
   check out this case
   n = 2
   both heaps having 2 coins
   player 2 will win i think
 
   On Wed, Jun 15, 2011 at 6:26 PM, immanuel kingston 
   kingston.imman...@gmail.com wrote:
 
   Yes. I am wrong. As per the example, Player 2 will win if he plays
   efficiently.
 
   Let me put my solution this way,
 
   If all the the heaps are of size  1 the Player 1 can win always.
 
   Thanks,
   Immanuel
 
   On Wed, Jun 15, 2011 at 5:36 PM, sunny agrawal 
 sunny816.i...@gmail.com
wrote:
 
   consider the case.
   n = 2;
   heap 1 - no of coins 1
   heap 2 - no of coins 2
 
   On Wed, Jun 15, 2011 at 5:34 PM, sunny agrawal 
   sunny816.i...@gmail.com wrote:
 
   i think u r wrong
   what if heap size -1 is 0
   i think one should pick atleast one coin else game will draw
 
   On Wed, Jun 15, 2011 at 5:17 PM, immanuel kingston 
   kingston.imman...@gmail.com wrote:
 
   First Player can always win.
 
   For each heap
  Pick heap-size - 1 coins if this is not the n-1th heap
  Pick all coins from the heap if this the n-1th heap.
 
   Please correct me if i am wrong.
 
   Thanks,
   Immanuel
 
   On Wed, Jun 15, 2011 at 3:13 PM, Piyush Sinha 
   ecstasy.piy...@gmail.com wrote:
 
   *There are n heaps of coin(numbered from 0 to n-1) with atleast
 1
   coin in each heap. There are 2 players. First player can pick
 any no. of
   coins from the least numbered heap, then the second player can
 pick any no.
   of coins from the least numbered heap. Unless it is emptied, the
 player cant
   move on to the next heap. The player who picks the last coin
 wins. Design an
   algorithm for predicting the winner.*
 
   --
   *Piyush Sinha*
   *IIIT, Allahabad*
   *+91-8792136657*
   *+91-7483122727*
   *https://www.facebook.com/profile.php?id=10655377926*
 
--
   You received this message because you are subscribed to the
 Google
   Groups Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com
 .
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
--
   You received this message because you are subscribed to the
 Google
   Groups Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
   --
   Sunny Aggrawal
   B-Tech IV year,CSI
   Indian Institute Of Technology,Roorkee
 
   --
   Sunny Aggrawal
   B-Tech IV year,CSI
   Indian Institute Of Technology,Roorkee
 
--
   You received this message because you are subscribed to the Google
   Groups Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
--
   You received this message because you are subscribed to the Google
   Groups Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
   --
   Sunny Aggrawal
   B-Tech IV year,CSI
   Indian Institute Of Technology,Roorkee
 
--
   You received this message because you are