Re: [algogeeks] Re: sqrt function...
binary search!!! :) On Sat, Sep 24, 2011 at 11:38 PM, sunny agrawal sunny816.i...@gmail.comwrote: let x be the number initialize ans to some value like x or x/2 now repeatedly do the following ans = (ans + x/ans)/2 each time you perform this operation you will move closer to the sqrt value and depending upon the precision required stop On Sat, Sep 24, 2011 at 11:17 PM, siddharth srivastava akssps...@gmail.com wrote: On 24 September 2011 13:45, shady sinv...@gmail.com wrote: one of the simplest way is to do binary search... :) +1 On Sat, Sep 24, 2011 at 8:42 PM, teja bala pawanjalsa.t...@gmail.comwrote: http://www.geeksforgeeks.org/archives/3187 check dis one. -- 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. -- Regards Siddharth Srivastava -- 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. V 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.
Re: [algogeeks] All valid dictionary words must be found and printed.
construct a trie.. then a simple recursion on the trie ll do ... :) any standard tutorial on tries ll help u build one ... then the recursion part should look something like this, start scanning from root of tire. if(end of word is found) { take is as a word, start searching from root of a trie + consider this as a prefix and proceed from the current state itself } else proceed to next state On Mon, Sep 19, 2011 at 8:20 PM, Sangeeta sangeeta15...@gmail.com wrote: given an array of characters without spaces and a dictionary.All valid dictionary words must be found and printed. i/p : BANKERKCATXYWOMAN. o/p: BANK BANKER CAT WOMAN MAN (the only function you could use for dictionary is dictionary.findword(char *str) which returns a Boolean value). Eg. Dictionary.findword(“bank”) =true Dictionary.findword(“hj”) =false -- 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] All valid dictionary words must be found and printed.
didnt read the question properly ... ignore ma post !! :/ On Mon, Sep 19, 2011 at 8:44 PM, Yogesh Yadav medu...@gmail.com wrote: i=0; char *str; while(a[i]!=NULL) { j=0; while(j!=i) { for(k=j;k=i;k++) { l=0; str[l]=a[j]; } if(Dictionary.findword(str)) printf(str); j++; } } ... On Mon, Sep 19, 2011 at 8:20 PM, Sangeeta sangeeta15...@gmail.com wrote: given an array of characters without spaces and a dictionary.All valid dictionary words must be found and printed. i/p : BANKERKCATXYWOMAN. o/p: BANK BANKER CAT WOMAN MAN (the only function you could use for dictionary is dictionary.findword(char *str) which returns a Boolean value). Eg. Dictionary.findword(“bank”) =true Dictionary.findword(“hj”) =false -- 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. -- 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] spoj coin tossing
thanks *Shashi* !!! http://deepblue.lib.umich.edu/bitstream/2027.42/24435/1/708.pdf this one is good to :) On Wed, Aug 24, 2011 at 5:32 PM, shashi kant shashiski...@gmail.com wrote: http://www.se.cuhk.edu.hk/~seem3570/12-pattern.pdf here is the solution to this On Wed, Aug 24, 2011 at 7:25 AM, keyankarthi keyankarthi1...@gmail.comwrote: http://www.spoj.pl/problems/MAIN8_D/ i tried solving this problem any ideas...?? for second test case 'htht' the states i considered are 1 T - (1/2) * x+1 2 HH - (1/4) * x+2 3 HTT - (1/8) * x+3 4 HTHH - (1/16) * x+4 5 HTHT - (1/16)(final state) x is the expected no of coins. x= 1 + 2+3+4+5 gives 16x=15x+26 x=26. answer given is 20... can any one explain this, -- 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. -- *Shashi Kant * ***Think positive and find fuel in failure* *+919002943948 * *RD engineer , Tejas Networks Ltd Banglore. * -- 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] spoj coin tossing
^typo On Wed, Aug 24, 2011 at 6:46 PM, keyan karthi keyankarthi1...@gmail.comwrote: thanks *Shashi* !!! http://deepblue.lib.umich.edu/bitstream/2027.42/24435/1/708.pdf this one is good to :) On Wed, Aug 24, 2011 at 5:32 PM, shashi kant shashiski...@gmail.comwrote: http://www.se.cuhk.edu.hk/~seem3570/12-pattern.pdf here is the solution to this On Wed, Aug 24, 2011 at 7:25 AM, keyankarthi keyankarthi1...@gmail.comwrote: http://www.spoj.pl/problems/MAIN8_D/ i tried solving this problem any ideas...?? for second test case 'htht' the states i considered are 1 T - (1/2) * x+1 2 HH - (1/4) * x+2 3 HTT - (1/8) * x+3 4 HTHH - (1/16) * x+4 5 HTHT - (1/16)(final state) x is the expected no of coins. x= 1 + 2+3+4+5 gives 16x=15x+26 x=26. answer given is 20... can any one explain this, -- 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. -- *Shashi Kant * ***Think positive and find fuel in failure* *+919002943948 * *RD engineer , Tejas Networks Ltd Banglore. * -- 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.
[algogeeks] spoj- coin tossing
http://www.spoj.pl/problems/MAIN8_D/ i tried solving this problem any ideas...?? for second test case 'htht' the states i considered are 1 T - (1/2) * x+1 2 HH - (1/4) * x+2 3 HTT - (1/8) * x+3 4 HTHH - (1/16) * x+4 5 HTHT - (1/16)(final state) x is the expected no of coins. x= 1 + 2+3+4+5 gives 16x=15x+26 x=26. answer given is 20... can any one explain this, -- 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] priority_queue
priority_queueobject, vector of object, greaterobject On 8/15/11, Zack sandeep.masum4...@gmail.com wrote: how i use STL,s prority_queue as a min heap..? -- 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. -- Sent from my mobile device -- 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] priority_queue
priority_queuepairint,int, vectorpairint,int , greater pair int, int here pair. First is used for comparing If you replace greater with lower , you get max heap If you use some structure... You have to define a bool function in tat case.. On 8/15/11, sandeep pandey sandeep.masum4...@gmail.com wrote: would u pls elaborate this..? -- 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. -- Sent from my mobile device -- 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] Design .. how to attack ???
First thing tat should come to your mind s ' requirements ' ask him wat de requirements are. He will expect tat.. On 8/12/11, MAC macatad...@gmail.com wrote: Hi guys , Can anyone help me in understanding what is expected when some some one asks you design a car rental system . Exactly what all is required to be told to the interviewer . -- thanks --mac -- 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. -- Sent from my mobile device -- 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] MS question
May be this way We dont display de title of a movie as a thumbnail So may be the first frame which has a wide distribution of colours , assuring it has some other part of de clip other than de title.. Ignore this if it sounds funny...!! On 8/9/11, *$* gopi.komand...@gmail.com wrote: I guess , it can be done using indexing , with time stamp as key , and frame pointer as data .. Please correct me if I am wrong. On Tue, Aug 9, 2011 at 11:03 PM, Priyanshu priyanshuro...@gmail.com wrote: Anyone?? Regards, Priyanshu Gupta On Fri, Aug 5, 2011 at 6:09 PM, priyanshu priyanshuro...@gmail.comwrote: Give an efficient algorithm to determine which part of the video should be displayed as a thumbnail?? -- 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. -- Thx, --Gopi -- 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. -- Sent from my mobile device -- 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] Duplicates in a string
u can use a bool array size- 26 and do char[i]-'A' = 1 , check it to decide the first instance of the character. this can be done in O(n). u can even use bit mask to make ur code look better ( ;) ) On 8/5/11, priya v pria@gmail.com wrote: If an additional storage is used to store the frequency / marker searching the frequency/marker in the array would require an additional nested loop. Would it still be O(n)? On Fri, Aug 5, 2011 at 8:36 PM, kartik sachan kartik.sac...@gmail.comwrote: I think in this case count sort type thing would work better way just take a array of max 26(as 26 CHARACTER ARE THERE) and using index as count['M']=store how many times M has comes similary store other character now print array whose value 0 but IN this case u might lost the ORDER..(but that can be done using binary search using T(log(n)) the total time complexcity is O(n) -- 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. -- 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: latest google interview questions
:D :D r u serious dude ?? On 8/3/11, Puneet Gautam puneet.nsi...@gmail.com wrote: @Utkarsh: How did u get the intern...? it cant be ...!!! Who is the moderator of this group..? I want this thread be removed immediately from this group...!!! pls do it... On 8/3/11, kaustubh kaustubh.c...@gmail.com wrote: You've got to be kiddin' me... On Aug 3, 12:55 am, UTKARSH SRIVASTAV usrivastav...@gmail.com wrote: hi I got intern in google ...but i was not able to do some question of written paper 1. main() { printf(hello);} OUTPUT- hello Why the output is coming hello? 2. Who developed C language ? I gave the answer Yashwant Kanetkarbut the interviewer said it was Dennis Ritchie...can anyone please tell me who is Dennis Ritchie -- * * -- 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. -- 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] Tug of War
if it is spoj -tug , then the problem gets reduced to knapsack dp which is used for subset sum calculation :) since u just have to print yes or no break once the sum count becomes '2' for some sum. On 7/30/11, Amol Sharma amolsharm...@gmail.com wrote: @saurabh- your algo has very high probability of failure take the case 9,7,8,4,3,1 acc to ur algo group 1 is 9,8,3 strength =20 group 2 is 7,4,2 strength =13 but it is possible to divide them into 2 equal grp's take G1 - 9,4,3 total =16 G2 - 7,8,1 total =16 so we have to think of some better algo -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad On Sat, Jul 30, 2011 at 5:51 PM, shubham shubh2...@gmail.com wrote: hey sylvester, just clarify the problem .. Is it such that in forming the group some people can be left out or the sum of the number of people in both partitions is equal to the total number of people -- 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/-/gVAGoc_nYhAJ. 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. -- 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] Amazon Question
@kavitha: u can use back tracking to print all the substring for a string .. pseudo code should look some thing like this: void next_perm(string st,int pos) { if(pos==length) { coutst; return; } for(int i=pos;ilength;i++) { swap(st,i,pos); next_perm(st,i+1); swap(st,i,pos); } } On 7/26/11, ankit sambyal ankitsamb...@gmail.com wrote: @Swetha :Number of possible sub strings of a string of length n is of the order of n^2. So, there can,t be a better solution than O(n^2) -- 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] Amazon Question
oops .. permutation pardon me guys !!! On 7/26/11, keyan karthi keyankarthi1...@gmail.com wrote: @kavitha: u can use back tracking to print all the substring for a string .. pseudo code should look some thing like this: void next_perm(string st,int pos) { if(pos==length) { coutst; return; } for(int i=pos;ilength;i++) { swap(st,i,pos); next_perm(st,i+1); swap(st,i,pos); } } On 7/26/11, ankit sambyal ankitsamb...@gmail.com wrote: @Swetha :Number of possible sub strings of a string of length n is of the order of n^2. So, there can,t be a better solution than O(n^2) -- 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] Unique characters in a string
yup tat should work fine :) :) On Sat, Jul 23, 2011 at 10:03 AM, rajeev bharshetty rajeevr...@gmail.comwrote: Use Quick sort to sort the characters of a string (qsort is inplace sorting ) then check for consecutive characters in the array, if they are same then the string is not unique else unique .(use builtin qsort in C .) No additional data structure is used ... What do u think of this guys ?? On Sat, Jul 23, 2011 at 9:52 AM, Reynald reynaldsus...@gmail.com wrote: Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures? -- 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. -- Regards Rajeev N B http://www.opensourcemania.co.cc -- 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] Sorting in O(n)
counting sort ll help to some extent... find the min and max element O(n) now u just need an array of size max-min to store the values then just traverse the list and while updating u do value+min... still it is not suitable if the magnitude is high. On Sat, Jul 23, 2011 at 9:45 AM, Ankur Khurana ankur.kkhur...@gmail.comwrote: n logn merge sort.count sort only when range is known. On Sat, Jul 23, 2011 at 1:35 AM, sunny agrawal sunny816.i...@gmail.comwrote: Cannot be done in O(N) if elements of list can take any value because then counting sort wont help On Sat, Jul 23, 2011 at 1:24 AM, Pankaj jatka.oppimi...@gmail.comwrote: For linklist? How On Sat, Jul 23, 2011 at 1:23 AM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: use counting sort.. On Sat, Jul 23, 2011 at 1:22 AM, rShetty rajeevr...@gmail.com wrote: How to sort Linked lists in O(n) time ?? Give the algorithm or the explanation or clue to tackle the problem -- 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. -- Regards, Kamakshi kamakshi...@gmail.com -- 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 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. -- Ankur Khurana Computer Science Netaji Subhas Institute Of Technology Delhi. -- 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] Unique characters in a string
u can use an integer as a bit mask to do this... by setting the alphabet-'a' th bit, and checking the same.. On Sat, Jul 23, 2011 at 9:52 AM, Reynald reynaldsus...@gmail.com wrote: Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures? -- 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] c aps can some one explain this pls :)
@boobal can u pls elaborate on sequence points @atul i compiled this in ubuntu On Mon, Jul 18, 2011 at 3:13 PM, Boobal Subramaniyam booban...@gmail.comwrote: sequence points... On Mon, Jul 18, 2011 at 3:11 PM, Amol Sharma amolsharm...@gmail.comwrote: it's not defined in the standard.unpredictable behaviour !! -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad On Mon, Jul 18, 2011 at 2:36 PM, keyan karthi keyankarthi1...@gmail.comwrote: #includeiostream using namespace std; int main() { int p=1; printf(%d %d %d %d,++p,p++,p++,++p); } output : 5 3 2 5 -- 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. -- with pleasure boobal -- 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] c aps can some one explain this pls :)
thanks ppl :) On Mon, Jul 18, 2011 at 3:59 PM, schrodinger 6fae1ce6347...@gmail.comwrote: AFAIK, official answer is due to undefined behavior. -- 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/-/EAWuaDE1CIcJ. 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] Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
can be done in NlogN take a node, say 'a' check if k-a exists in the tree(logN) On Sat, Jul 16, 2011 at 7:58 PM, sourabh jakhar sourabhjak...@gmail.comwrote: convert into doubly linked list and than apply simple algo of finding two element with a sum On Sat, Jul 16, 2011 at 7:54 PM, saurabh singh saurab...@gmail.comwrote: Check https://groups.google.com/group/algogeeks/browse_thread/thread/e8735bcdbf4c956/c49018d0eac8070b?hl=enlnk=gstq=saurabh8c#c49018d0eac8070b On Sat, Jul 16, 2011 at 7:50 PM, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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. -- Saurabh Singh B.Tech (Computer Science) MNNIT ALLAHABAD -- 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. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- 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] help..
yup :) On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah shalinisah.luv4cod...@gmail.com wrote: i guess the no. of 1s in the binary representation of the number is the answer..for 6 its 2... On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com wrote: the length of the rope is l units. I can only cut any rope into two halves. for example if the length of the rope is 8 and we need a length of rope 6 we first cut into two halves and we get 4, 4 now we cut any of the half again and we get 4,2,2 now we can merge 4 and 2 and form a rope of length 6. in this example we need a minimum of 2 cuts to get the length of rope 6 from 8 assume that l is always a power of 2 and we need always a even length of rope from it how to find the number of minimum cuts needed to get the new rope?. -- 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. -- 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] Sum to K problem
http://en.wikipedia.org/wiki/Subset_sum_problem http://en.wikipedia.org/wiki/Subset_sum_problem this should help u :) knapsack like dp :) On Mon, Jun 20, 2011 at 11:55 AM, Navneet Gupta navneetn...@gmail.comwrote: Given a set of integers , find a set of numbers such that they sum to a given number k . Notice the set of numbers can have 2 or more than 2 numbers. --Navneet -- 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: Find an element which is not present?
one way might be... find min element, max element declare a array buffer[max-min] memset this to -1 for( i=0 to size ) buffer[input[i]-min elemet]=1 now check in O(n) the first position that has a -1 in array buffer, this position + min element is the answer but this uses lotta extra memory :( one easy way is to sort, run a loop from a[0] till the element not found rite. pardon me if this sounds insane !! On Tue, Jun 21, 2011 at 6:39 PM, Nitish Garg nitishgarg1...@gmail.comwrote: One thing more it is not the question in which the array elements are from 1 to N and one element is missing. -- 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/-/FNbt3O17ArwJ. 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: spoj problem chairs
dp(int chair,int person,bool previous) if(previous) dp(chair-1,person,0) else dp(chair-1,person-1,1)+dp(chair-1,person,0) with basic conditions as it is a circle.. if person is placed in first chair u cant place a person in last chair On Tue, Jun 21, 2011 at 7:38 PM, shady sinv...@gmail.com wrote: what will be the dynamic programming solution to the above problem ? can anyone explain the states of the dp ? On Mon, Jun 20, 2011 at 6:53 PM, oppilas . jatka.oppimi...@gmail.comwrote: I think you have not read the question carefully. Please read it again and try to ans for small values of n,k first. for k=1, answer will be always 1. On Mon, Jun 20, 2011 at 6:31 PM, saurabh singh saurab...@gmail.comwrote: O.K can anyone suggest the combinatorial solution.I thought it this way- Assume k chairs as one chair.Now no. of ways arranging these chairs would be ((n-k+1)-1)! and the number of ways of arranging the k chairs would be k!. So the no. of ways of arranging the chairs so that they are always together becomes..(n-1)!-(n-k)!*(k)!? Where was I wrong in the approach?Please correct me, On Mon, Jun 20, 2011 at 5:36 PM, RITESH SRIVASTAV riteshkumar...@gmail.com wrote: @Saurabh Your formula is incorrect. for input : 5 2 the answer should be 5 but your program gives 12 as output. On Jun 19, 11:35 pm, abc abc may.i.answ...@gmail.com wrote: @above Better you ask it on spoj forum On Sun, Jun 19, 2011 at 7:27 PM, saurabh singh saurab...@gmail.com wrote: I am getting WA for this problem.I dont know whether its case of overflow or I have come up with a wrong formula, https://www.spoj.pl/problems/CHAIR/ I am coding in python so I dont think there is probblem of overflow. def f(n): if n0: return 0 if n==0: return 1 i=n prod=1 while i0 : prod*=i i-=1 return prod n=input() k=input() if k==1: print n elif 2*kn: print 0 else : x=f(n-1) y=f(n-k)*f(k) print (x-y)%13 -- Saurabh Singh B.Tech (Computer Science) MNNIT ALLAHABAD -- 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. -- Saurabh Singh B.Tech (Computer Science) MNNIT ALLAHABAD -- 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. -- 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: find output.
hi friends is a string literal.. ie the string hi friends is stored somewhere and a pointer to its base address is returned to pointer p at the time of initialization... u can always make use of this pointer to traverse / access the literal but u cant alter tat in the code, u r trying to do a ++ operation, which throws a seg fault On Thu, Jun 16, 2011 at 2:16 PM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: i still din't get the solution..please explain.. On 6/16/11, LALIT SHARMA lks.ru...@gmail.com wrote: ++*p++ == ++(*p++) , increments the value stored at p , and also increments p . On Thu, Jun 16, 2011 at 1:10 PM, sunny agrawal sunny816.i...@gmail.comwrote: The place where strict constness is not enforced is with character array literals. You can say char* cp = howdy; and the compiler will accept it without complaint. This is technically an error because a character array literal (“howdy” in this case) is created by the compiler as a constant character array, and the result of the quoted character array is its starting address in memory. Modifying any of the characters in the array is a runtime error, although not all compilers enforce this correctly. So character array literals are actually constant character arrays. Of course, the compiler lets you get away with treating them as nonconst because there’s so much existing C code that relies on this. However, if you try to change the values in a character array literal, the behavior is undefined, although it will probably work on many machines. If you want to be able to modify the string, put it in an array: char cp[] = howdy; Since compilers often don’t enforce the difference you won’t be reminded to use this latter form and so the point becomes rather subtle. On Thu, Jun 16, 2011 at 12:59 PM, amit kumar amitthecoo...@gmail.comwrote: //kk //In place of char *p=hai friends,*p1; if i declare as char p[]=hai friends; char *p1; //then ?? On Thu, Jun 16, 2011 at 8:16 AM, DIPANKAR DUTTA dutta.dipanka...@gmail.com wrote: It's ok.. char *p=hai friends...not correct bcz you did allocate memory for that string but assiging poiter to the base address.. from where gcc will get the bse address of that string when u r not actually allocate memory for it? thus it generate SIGSEG signal and give invalid memory address...ie. segmentation fault use malloc or use char p[]=..; On Thu, Jun 16, 2011 at 4:49 AM, DK divyekap...@gmail.com wrote: Gives me a SEGFAULT on gcc. Probably due to undefined behaviour. -- DK http://twitter.com/divyekapoor http://www.divye.in -- 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/-/QVAjKMQiWvoJ. 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. -- Thanks and Regards, -- *DIPANKAR DUTTA* Visiting Research Scholar Dept of Computing, Macquarie University, Sydney, Australia ph.no-+61 2 98509079 ( Mon-Fri 10:15-7:00) Sydney time email: dipankar.du...@mq.edu.au -- 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 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. -- Lalit Kishore Sharma, IIIT Allahabad (Amethi Capmus), 6th Sem. -- 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
Re: [algogeeks] MSFT Q
we can even add word completion :) On Wed, Jun 15, 2011 at 5:25 PM, immanuel kingston kingston.imman...@gmail.com wrote: Use a trie data structure and pre-load it with all the words of a dictionary. Thanks, Immanuel On Wed, Jun 15, 2011 at 3:06 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: *How will you design a SpellChecker for an e-mail application?* -- *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. -- 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] Please explain this problem
upper_bound and lower_bound does a binary search to get count of alike terms.. which u tend to sum of to get the ans.. out of the two arrays, u need to sort one array.. this will be teh vector in which u do the binary search wit every element of un sorted array.. this is the approach i used... :) hope this helps... the above functions defined in algorithm On Sun, Jun 12, 2011 at 12:34 PM, nicks crazy.logic.k...@gmail.com wrote: and here is my code I'm Getting TLE i tried to implement binary search but failed bcoz how will i be able to trace the value from one vector into another vector if there are any multiple occureneces of any value(i mean i have count them).in this code i i have used count of algorithm which may be expensive...suggest a better way plz...thnx in advance !! #includevector #includeiostream #includealgorithm #includecstdio #includecmath using namespace std; int main() { int num,ans=0,value,i,j,k,t,a,b,c,d,e,f; scanf(%d,num); vectorint val,a1,a2; for(i=0;inum;i++) { scanf(%d,t); val.push_back(t); } for(i=0;inum;i++) { a=val[i]; for(j=0;jnum;j++) { b=val[j]; for(k=0;knum;k++) { c=val[k]; t=a*b+c; a1.push_back(t); } } } for(i=0;inum;i++) { d=val[i]; for(j=0;jnum;j++) { e=val[j]; for(k=0;knum;k++) { f=val[k]; t=(f+e)*d; a2.push_back(t); } } } vectorint::iterator itr; for(itr=a1.begin();itr!=a1.end();itr++) { value=*itr; ans+=count(a2.begin(),a2.end(),value); } printf(%d\n,ans); return 0; } On Sat, Jun 11, 2011 at 11:57 PM, saurabh singh saurab...@gmail.comwrote: OK here is my code #includestdio.h #includealgorithm #includeutility using namespace std; int compareints (const void * a, const void * b) { return ( *(long*)a - *(long*)b ); } int main() { int n,s[101],a,b,c,d,e,f; long p1[19],p2[19]; int i,j,k; scanf(%d,n); for(i=0;in;i++) scanf(%d,s[i]); //sort(s,s+i); k=0; for(i=0;in;i++) { for(j=0;jn;j++) { for(int l=0;ln;l++) { if(s[l]) p1[k++]=(s[i]+s[j])*s[l]; } } } //sort(p1,p1+k); int x=0; for(i=0;in;i++) { for(j=0;jn;j++) { for(int l=0;ln;l++) { //if(s[l]!=0) p2[x++]=(s[i]*s[j])+s[l]; } } } sort(p2,p2+x); long *pItem; long count=0; for(i=0;ik;i++) { pItem = (long*) bsearch (p1[i], p2, x, sizeof (long), compareints); if(pItem){ long *tmp=pItem; if(pItem==p2)while(*(tmp)==p1[i]tmpp2+x){ count++;tmp++;} else if(pItem==(p2+(x-1))) { while(pItem=p2*(pItem)==p1[i]){count++;pItem--;}} else{ tmp++; while(*(tmp)==p1[i]tmpp2+x){ count++;tmp++;} while(pItem=p2*(pItem)==p1[i]){count++;pItem--;} } //count++; } } printf(%ld\n,count); //for(i=0;ik;i++) printf(%ld ,p1[i]);printf(\n); //for(i=0;ix;i++) printf(%ld ,p2[i]);printf(\n); return 0; } Why is it getting segmentation fault? -- 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. -- 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] Please explain this problem
hint: u ve commented some vital part of ur code ;) On Sun, Jun 12, 2011 at 12:46 PM, saurabh singh saurab...@gmail.com wrote: I did used the library functions but I am getting sigsegv after 0.03 s.I cant understand why?I am presuming sumthing wrong about the implemenatation of bsearch? I am assuming bsearch is returning a pointer to the first found element. On Sun, Jun 12, 2011 at 12:41 PM, keyan karthi keyankarthi1...@gmail.comwrote: upper_bound and lower_bound does a binary search to get count of alike terms.. which u tend to sum of to get the ans.. out of the two arrays, u need to sort one array.. this will be teh vector in which u do the binary search wit every element of un sorted array.. this is the approach i used... :) hope this helps... the above functions defined in algorithm On Sun, Jun 12, 2011 at 12:34 PM, nicks crazy.logic.k...@gmail.comwrote: and here is my code I'm Getting TLE i tried to implement binary search but failed bcoz how will i be able to trace the value from one vector into another vector if there are any multiple occureneces of any value(i mean i have count them).in this code i i have used count of algorithm which may be expensive...suggest a better way plz...thnx in advance !! #includevector #includeiostream #includealgorithm #includecstdio #includecmath using namespace std; int main() { int num,ans=0,value,i,j,k,t,a,b,c,d,e,f; scanf(%d,num); vectorint val,a1,a2; for(i=0;inum;i++) { scanf(%d,t); val.push_back(t); } for(i=0;inum;i++) { a=val[i]; for(j=0;jnum;j++) { b=val[j]; for(k=0;knum;k++) { c=val[k]; t=a*b+c; a1.push_back(t); } } } for(i=0;inum;i++) { d=val[i]; for(j=0;jnum;j++) { e=val[j]; for(k=0;knum;k++) { f=val[k]; t=(f+e)*d; a2.push_back(t); } } } vectorint::iterator itr; for(itr=a1.begin();itr!=a1.end();itr++) { value=*itr; ans+=count(a2.begin(),a2.end(),value); } printf(%d\n,ans); return 0; } On Sat, Jun 11, 2011 at 11:57 PM, saurabh singh saurab...@gmail.comwrote: OK here is my code #includestdio.h #includealgorithm #includeutility using namespace std; int compareints (const void * a, const void * b) { return ( *(long*)a - *(long*)b ); } int main() { int n,s[101],a,b,c,d,e,f; long p1[19],p2[19]; int i,j,k; scanf(%d,n); for(i=0;in;i++) scanf(%d,s[i]); //sort(s,s+i); k=0; for(i=0;in;i++) { for(j=0;jn;j++) { for(int l=0;ln;l++) { if(s[l]) p1[k++]=(s[i]+s[j])*s[l]; } } } //sort(p1,p1+k); int x=0; for(i=0;in;i++) { for(j=0;jn;j++) { for(int l=0;ln;l++) { //if(s[l]!=0) p2[x++]=(s[i]*s[j])+s[l]; } } } sort(p2,p2+x); long *pItem; long count=0; for(i=0;ik;i++) { pItem = (long*) bsearch (p1[i], p2, x, sizeof (long), compareints); if(pItem){ long *tmp=pItem; if(pItem==p2)while(*(tmp)==p1[i]tmpp2+x){ count++;tmp++;} else if(pItem==(p2+(x-1))) { while(pItem=p2*(pItem)==p1[i]){count++;pItem--;}} else{ tmp++; while(*(tmp)==p1[i]tmpp2+x){ count++;tmp++;} while(pItem=p2*(pItem)==p1[i]){count++;pItem--;} } //count++; } } printf(%ld\n,count); //for(i=0;ik;i++) printf(%ld ,p1[i]);printf(\n); //for(i=0;ix;i++) printf(%ld ,p2[i]);printf(\n); return 0; } Why is it getting segmentation fault? -- 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. -- You received this message because you
Re: [algogeeks] Please explain this problem
@saurabh,nick: u cant divide by 0.. u need to check it while generating the array.. i used somethin like this... 1. void fun(int n) 2. { 3. int a,b,cl; 4. for(a=0;an;a++) 5. { 6. for(b=0;bn;b++) 7. { 8. for(cl=0;cln;cl++) 9. { 10. v.push_back((inp[a]*inp[b])+inp[cl]); 11. if(inp[cl]) 12. c.push_back(inp[cl]*(inp[a]+inp[b])); 13. } 14. } 15. } 16. } u cant divide by 0.. tats why u get tat runtime error... fix it :) On Sun, Jun 12, 2011 at 1:52 PM, saurabh singh saurab...@gmail.com wrote: I am trying really hard to get this one fixed,still cant find any problem..:-( On Sun, Jun 12, 2011 at 1:45 PM, nicks crazy.logic.k...@gmail.com wrote: forgot to attach the code...here is the modified code.. #includevector #includeiostream #includealgorithm #includecstdio #includecmath using namespace std; int main() { int num,ans=0,value,i,j,k,t,a,b,c,d,e,f; scanf(%d,num); vectorint val,a1,a2; for(i=0;inum;i++) { scanf(%d,t); val.push_back(t); } for(i=0;inum;i++) { a=val[i]; for(j=0;jnum;j++) { b=val[j]; for(k=0;knum;k++) { c=val[k]; t=a*b+c; a1.push_back(t); } } } for(i=0;inum;i++) { d=val[i]; for(j=0;jnum;j++) { e=val[j]; for(k=0;knum;k++) { f=val[k]; t=(f+e)*d; a2.push_back(t); } } } sort(a2.begin(),a2.end()); vectorint::iterator itr; for(itr=a1.begin();itr!=a1.end();itr++) { value=*itr; //ans+=count(a2.begin(),a2.end(),value); ans+=upper_bound(a2.begin(),a2.end(),value)-lower_bound(a2.begin(),a2.end(),value); } printf(%d,ans); return 0; } On Sun, Jun 12, 2011 at 1:07 AM, nicks crazy.logic.k...@gmail.comwrote: @keyan..your advice was really very helpful...the time limit has come under control ...1.4s but now i am getting WA though my code is giving right ans for the test cases...can you plz help me in figuring out where it fails .. On Sun, Jun 12, 2011 at 12:59 AM, keyan karthi keyankarthi1...@gmail.com wrote: hint: u ve commented some vital part of ur code ;) On Sun, Jun 12, 2011 at 12:46 PM, saurabh singh saurab...@gmail.comwrote: I did used the library functions but I am getting sigsegv after 0.03 s.I cant understand why?I am presuming sumthing wrong about the implemenatation of bsearch? I am assuming bsearch is returning a pointer to the first found element. On Sun, Jun 12, 2011 at 12:41 PM, keyan karthi keyankarthi1...@gmail.com wrote: upper_bound and lower_bound does a binary search to get count of alike terms.. which u tend to sum of to get the ans.. out of the two arrays, u need to sort one array.. this will be teh vector in which u do the binary search wit every element of un sorted array.. this is the approach i used... :) hope this helps... the above functions defined in algorithm On Sun, Jun 12, 2011 at 12:34 PM, nicks crazy.logic.k...@gmail.comwrote: and here is my code I'm Getting TLE i tried to implement binary search but failed bcoz how will i be able to trace the value from one vector into another vector if there are any multiple occureneces of any value(i mean i have count them).in this code i i have used count of algorithm which may be expensive...suggest a better way plz...thnx in advance !! #includevector #includeiostream #includealgorithm #includecstdio #includecmath using namespace std; int main() { int num,ans=0,value,i,j,k,t,a,b,c,d,e,f; scanf(%d,num); vectorint val,a1,a2; for(i=0;inum;i++) { scanf(%d,t); val.push_back(t); } for(i=0;inum;i++) { a=val[i]; for(j=0;jnum;j++) { b=val[j]; for(k=0;knum;k++) { c=val[k]; t=a*b+c; a1.push_back(t); } } } for(i=0;inum;i++) { d=val[i]; for(j=0;jnum;j++) { e=val[j]; for(k=0;knum;k++) { f=val[k]; t=(f+e)*d; a2.push_back(t); } } } vectorint::iterator itr; for(itr=a1.begin();itr!=a1.end();itr++) { value=*itr; ans+=count(a2.begin(),a2.end(),value); } printf(%d\n,ans); return 0; } On Sat, Jun 11, 2011 at 11:57 PM, saurabh singh saurab...@gmail.com wrote: OK here is my code #includestdio.h #includealgorithm #includeutility
Re: [algogeeks] Re: SPOJ THRBL
k=query(x,y-1) if(k==x) count++ with this change ur code ACs :) On Sat, Jun 11, 2011 at 1:24 PM, Radhika Renganathan radi.coo...@gmail.comwrote: i did the same prob wit range maximum query.. but im repeatedly getting wrong answer.. im stuck with this prob for a long time.. pls help.. my code: #includeiostream using namespace std; #includestdlib.h #includestdio.h int A[50010]; int M[999]; void initialize(int node, int b, int e) { if (b == e) M[node] = b; else { initialize(2 * node, b, (b + e) / 2); initialize(2 * node + 1, (b + e) / 2 + 1,e); if (A[M[2 * node]] = A[M[2 * node + 1]]) M[node] = M[2 * node]; else M[node] = M[2 * node + 1]; } } int query(int node, int b, int e, int i, int j) { int p1, p2; if (i e || j b) return -; if (b = i e = j) return M[node]; p1 = query(2 * node, b, (b + e) / 2,i, j); p2 = query(2 * node + 1, (b + e) / 2 + 1, e, i, j); if (p1 == -) return p2; if (p2 == -) return p1; if (A[p1] = A[p2]) return p1; return p2; } int main() { int n,i,t,j,count=0,k,size; scanf(%d%d,n,t); for (i=1;i=n;i++) scanf(%d,A[i]); initialize(1,1,n); for(i=0;it;i++) { int x,y; scanf(%d%d,x,y); k=query(1,1,n,x,y); if(!(xk ky)) count++; } printf(%d,count); return 0; } On 6/11/11, KK kunalkapadi...@gmail.com wrote: Search Topcoder Tutorial Range Minimum Query @ Google... By few intuitive changes u can implement Range Maximum Query as well... -- 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. -- radhika .. :) -- 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] SPOJ THRBL
u construct a tree nlogn , every node answers a query.. (or u get ans with a recursion) in log(n) , so when u r doing a lot of query RMQ proves to be very fast On Fri, Jun 10, 2011 at 6:28 PM, nicks crazy.logic.k...@gmail.com wrote: ya i saw that in the comments on spoj someone suggested to use RMQcan you explain a bit moe how to implement RMQ and how it is helping in reducing the time !! On Fri, Jun 10, 2011 at 5:53 AM, saurabh singh saurab...@gmail.comwrote: Use Range Maximum Query. On Fri, Jun 10, 2011 at 4:15 PM, kartik sachan kartik.sac...@gmail.comwrote: how should we get TLE loop total running less than 10^6?? -- 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. -- Saurabh Singh B.Tech (Computer Science) MNNIT ALLAHABAD -- 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. -- 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] Please explain this problem
the nos can repeat :) ie the valid set may contain multiple instance of a same number.. hope this helps :) On Fri, Jun 10, 2011 at 9:31 AM, saurabh singh saurab...@gmail.com wrote: Problem link- ABCDEF https://www.spoj.pl/problems/ABCDEF/ Can someone please explain this problem.The problem says a,b,c,d,e,f belongs to S.But what if size of S is smaller than 6? I know i am missing sumthing very trivialhelp plz. -- Saurabh Singh B.Tech (Computer Science) MNNIT ALLAHABAD -- 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] repeted element
abba as goel pointed out.. is the answer 'b' or 'a' .. ie does the order in which u encounter the character matters.. 'a' comes before 'b' here... if it is 'b' then a normal buf[txt[i]-'a']++ should do.. :) On Wed, Jun 8, 2011 at 8:48 AM, Shivaji Varma shivaji...@gmail.com wrote: This problem of finding first non-repeating element in an array is different from finding the first non-repeating character in a string. The latter is a pretty easy one. On Wed, Jun 8, 2011 at 12:12 AM, Anand anandut2...@gmail.com wrote: http://anandtechblog.blogspot.com/2011/06/first-repeating-character-in-string.html On Tue, Jun 7, 2011 at 9:30 AM, Apoorve Mohan apoorvemo...@gmail.comwrote: if there is no space complexity constraint then *hashing* can be used i guess On Tue, Jun 7, 2011 at 9:57 PM, Ashish Goel ashg...@gmail.com wrote: abba what will be first repeated element? Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Tue, Jun 7, 2011 at 12:06 AM, the coder coder.du...@gmail.comwrote: can we find the first repeated element in array in O(N) complexity. Array may contain more than 1 repeated elements. -- 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. -- regards Apoorve Mohan -- 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. -- 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: get rid of sohail panzer spam
:D :D On Wed, Jun 8, 2011 at 2:25 PM, Kunal Patil kp101...@gmail.com wrote: Automatic deletion will solve the trouble only for you not for the group as such messages are not reported spam.. [?] What i do is: When i login just type in search box 'panzer'...mark all...report spam and then delete from spam box..That way they are definitely reported as spams..[?] We can't create filter to report a message directly as a spam..[?][?] -- 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. 33A.gif323.gif360.gif
Re: [algogeeks] SPOJ ETF
dude.. u code says pi(3) =3 as its a prime... but pi(3) is 2 in the same way pi(2)=2 as per ur code.. but ans is 1... mend ur code for this... :) On Sun, Jun 5, 2011 at 9:20 PM, kartik sachan kartik.sac...@gmail.comwrote: @keyan then also it is given time limit exceed i don't know what to do..plzz help me plz my modified code is : # includestdio.h int main() { long long int phi[101]; long long int i,j,t1,k; scanf(%lld,t1); while(t1--) { scanf(%lld,k); phi[1]=1; for ( i=2; i=k; ++i) phi[i]=i; for ( i=2; i=k; ++i) if (phi[i]==i) // prime for ( j=i; j=k; j+=i) phi[j]=phi[j]/i*(i-1); printf(%lld\n,phi[k]); } return 0; } -- 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] SPOJ ETF
also tc page tat arun said says as follows... 1. If *p* is prime, then φ (*p*) = *p* - 1 and φ (*pa*) = *p** a* * (1 - 1/*p*) for any *a*. 2. If *m* and *n* are coprime, then φ (*m* * *n*) = φ (*m*) * φ (*n*). 3. If *n* = , then Euler function can be found using formula: φ (*n*) = *n* * (1 - 1/*p* 1) * (1 - 1/*p* 2) * ... * (1 - 1/*p k*) make sure u check this... i did the loop stuff in that page.. ve not tried ma hands on sieve... On Sun, Jun 5, 2011 at 9:20 PM, kartik sachan kartik.sac...@gmail.comwrote: @keyan then also it is given time limit exceed i don't know what to do..plzz help me plz my modified code is : # includestdio.h int main() { long long int phi[101]; long long int i,j,t1,k; scanf(%lld,t1); while(t1--) { scanf(%lld,k); phi[1]=1; for ( i=2; i=k; ++i) phi[i]=i; for ( i=2; i=k; ++i) if (phi[i]==i) // prime for ( j=i; j=k; j+=i) phi[j]=phi[j]/i*(i-1); printf(%lld\n,phi[k]); } return 0; } -- 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] SPOJ ETF
first time when i pre processed, my code timed out :P on calling it for every loop iteration my code passed !! may be tats the problem... On Sun, Jun 5, 2011 at 1:56 AM, kartik sachan kartik.sac...@gmail.comwrote: @arun.i got nothing from this link becoz i have made the program from that concept...give me some other hints.. -- 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] spoj problem acode
even if the left over string length is 1 so that the recursion can be fun(s,current_position-2), u still have the option for choosing a single character... do u get it?? thats where u go wrong... :) the rec call should be return fun(cur_length-1)+fun(cur_len-2) ... On Wed, Jun 1, 2011 at 3:34 PM, arun kumar kumar0...@gmail.com wrote: hey me getting wrong ans..can anyone pls help me out here s my code #includestdio.h #includeiostream #includestring #includecstring using namespace std; unsigned long long a[5001]={0}; unsigned long long fun(string s,int n) { if(n==0) return 1; if(a[n]) return a[n]; int c=0,d=0; c=s[n]-'0'; d=s[n-1]-'0'; unsigned long long ans=a[n]; // coutcdendl; if((d*10+c)=26 n!=1) ans+=fun(s,n-2); else if((d*10+c)=26) ans+=fun(s,0); if(d!=0) ans+=fun(s,n-1); return ans; } main() { string s; while(cins s[0]!='0') { memset(a,0,sizeof(a)); coutfun(s,s.size()-1); } } On Wed, Jun 1, 2011 at 3:30 PM, pacific :-) pacific4...@gmail.com wrote: Link : https://www.spoj.pl/problems/ACODE/ 25114 BEAN’, ‘BEAAD’, ‘YAAD’, ‘YAN’, ‘YKD’ ‘BEKD’. How many different decodings?” My soln , but i get TLE.Please help. #include iostream #include cstdio #include vector using namespace std; char * head; int result[5001]; int count(char * a ,int size) { if(result[a-head]!=0){ return result[a-head]; } if(size==1) return 1; else if (size==2) { if(a[0]'2') return 1; else return 2; } else { int temp = count(a+1,size-1); if(a[0]'2' || (a[0]=='2' a[1]'6')) { result[a-head] = temp ; return temp; } else { int r = temp+count(a+2,size-2); result[a-head] = r; return r; } } } int main() { char ch; cinch; while(ch!='0') { char input[5001]; int index=0; while(ch!='\n') { //input.push_back(ch-'0'); input[index]=ch; index++; scanf(%c,ch); } cinch; head = input ; for(int i=0;i=5000;i++) result[i]=0; coutcount(input,index)endl; } return 0; } -- regards, chinna. -- 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. -- 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] spoj problem acode
oops.. :P that an if didnt notice tat :D On Wed, Jun 1, 2011 at 8:34 PM, keyan karthi keyankarthi1...@gmail.comwrote: even if the left over string length is 1 so that the recursion can be fun(s,current_position-2), u still have the option for choosing a single character... do u get it?? thats where u go wrong... :) the rec call should be return fun(cur_length-1)+fun(cur_len-2) ... On Wed, Jun 1, 2011 at 3:34 PM, arun kumar kumar0...@gmail.com wrote: hey me getting wrong ans..can anyone pls help me out here s my code #includestdio.h #includeiostream #includestring #includecstring using namespace std; unsigned long long a[5001]={0}; unsigned long long fun(string s,int n) { if(n==0) return 1; if(a[n]) return a[n]; int c=0,d=0; c=s[n]-'0'; d=s[n-1]-'0'; unsigned long long ans=a[n]; // coutcdendl; if((d*10+c)=26 n!=1) ans+=fun(s,n-2); else if((d*10+c)=26) ans+=fun(s,0); if(d!=0) ans+=fun(s,n-1); return ans; } main() { string s; while(cins s[0]!='0') { memset(a,0,sizeof(a)); coutfun(s,s.size()-1); } } On Wed, Jun 1, 2011 at 3:30 PM, pacific :-) pacific4...@gmail.com wrote: Link : https://www.spoj.pl/problems/ACODE/ 25114 BEAN’, ‘BEAAD’, ‘YAAD’, ‘YAN’, ‘YKD’ ‘BEKD’. How many different decodings?” My soln , but i get TLE.Please help. #include iostream #include cstdio #include vector using namespace std; char * head; int result[5001]; int count(char * a ,int size) { if(result[a-head]!=0){ return result[a-head]; } if(size==1) return 1; else if (size==2) { if(a[0]'2') return 1; else return 2; } else { int temp = count(a+1,size-1); if(a[0]'2' || (a[0]=='2' a[1]'6')) { result[a-head] = temp ; return temp; } else { int r = temp+count(a+2,size-2); result[a-head] = r; return r; } } } int main() { char ch; cinch; while(ch!='0') { char input[5001]; int index=0; while(ch!='\n') { //input.push_back(ch-'0'); input[index]=ch; index++; scanf(%c,ch); } cinch; head = input ; for(int i=0;i=5000;i++) result[i]=0; coutcount(input,index)endl; } return 0; } -- regards, chinna. -- 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. -- 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] SPoj maximum sum subseuence
i used the following code.. getting wa #includeiostream #includealgorithm #includevector #includelimits.h #includemap using namespace std; typedef unsigned long long int ull; int main() { int t; cint; while(t--) { int n,sm=0; scanf(%d,n); vectorint v(n); mapint,int mp; for(int i=0;in;i++) scanf(%d,v[i]); int sum=INT_MIN,cur=0; for(int i=0;in;i++) { cur+=v[i]; mp[cur]++; if(cursum) { sum=cur; } if(cur0) cur=0; } //coutsum\tmp[sum]+mp[0]\n; printf(%d %d\n,sum,mp[sum]+mp[0]); } } On Mon, Mar 14, 2011 at 7:41 PM, tech rascal techrascal...@gmail.comwrote: @ankur: can u plz xplain ur approach?? On Sun, Mar 13, 2011 at 12:26 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: https://www.spoj.pl/problems/MAXSUMSQ/ Hi in above problem , i am getting TLE but according to given contraints , i think my code is good enough to run. Can any body help me here #include vector #include map #include algorithm #include cstring #include iostream #include cstdio #include cmath #include cstdlib #include climits #define VI vector int typedef long long int LL; using namespace std; VI v; LL x,nos; //finding maximum sum subsequence LL findx() { int sz=v.size(); LL maxsum=INT_MIN; int maxstart=0,maxend=0; LL currentsum=0; int currentstart=0,currentend=0; for(currentend=0;currentendsz;currentend++) { currentsum=currentsum+v[currentend]; if(currentsummaxsum) { maxsum=currentsum; maxstart=currentstart; maxend=currentend; } if(currentsum0) { currentstart=currentend+1; currentsum=0; } } return maxsum; } // main Program int main() { // freopen(input.txt,r,stdin); int test; int num; map LL , LL m; cintest; LL sum=0; int n; int i; while(test--) { sum=0; nos=0; m.clear(); m[0]=1; scanf(%d,n); v.resize(n); for(i=0;in;i++) { scanf(%d,v[i]); } x=findx(); nos=0; for(i=0;in;i++) { sum=sum+v[i]; nos=nos+m[sum-x]; m[sum]++; } coutx nosendl; } return 0; } -- 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. -- 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.