[algogeeks] Spoj AMR10D
http://www.spoj.com/problems/AMR10D/ A number is a multiple of 11, when its digits are given alternate signs (starting with positive from right) and added w.r.t the signs gives a number modulo 11. The question is asking to partition the given numbers into two groups say S1 and S2 such that the difference between their cardinalities is minimum and (sum of all elements in S1) - (sum of all elements in S2) is divisible by 11. The question looks like dp. d( i , c, s') = 1 if there exists a subset S of {a1,a2,...ai} such that elements of S sum to s' and S has cardinality c. A state like this will increase the running time. Please help. -- 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.
Re: [algogeeks] Spoj FARIDA
On Wed, May 22, 2013 at 9:45 AM, emmy foramlakh...@gmail.com wrote: problem : http://www.spoj.com/problems/FARIDA/ what is wrong with this code? The algorithm is pretty straight forward Is it ? 1000 1 1 1000 Your code gives 1001 as output. Desired output should be 2000. -- 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. -- 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.
[algogeeks] Spoj FARIDA
problem : http://www.spoj.com/problems/FARIDA/ what is wrong with this code? The algorithm is pretty straight forward #includestdio.h #includestdlib.h int main(void) { int t,n,i; scanf(%d,t); long long int s1,s2,s=0,a,temp; int c=1; while(t--) { scanf(%d,n); if(n==0) { printf(Case %d: 0\n,c); c++; continue; } scanf(%lld,s1); if(n==1) { printf(Case %d: %lld\n,c,s1); c++; continue; } scanf(%lld,s2); for(i=2;in;i++) { scanf(%lld,a); temp=s2; s2=s1+as2?s1+a:s2; s1=temp; } s=s1s2?s1:s2; printf(Case %d: %lld\n,c,s); c++; } // scanf(%d,i); return 0; } -- 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.
[algogeeks] SPOJ ABA12C
I have been trying to solve this problem - http://www.spoj.com/problems/ABA12C/ but am getting continuous WA. Now i have found a test case where my code gives wrong answer but am not able to find the fault in the logic. please help!! The code along with the test case for which i am getting wrong answer- http://ideone.com/w8Ek7V Explanation of recurrence. func(i,j,count) It evaluates the minimum ruppees needed to buy 'i' kgs of apples from first 'j' packets, buying exactly 'count' packets. Following are the cases: 1- For jth packet, if the value is '-1' we skip it and go to j-1th packet as jth packet is not available. func(i,j,count)= func(i,j-1, count) 2- If the value of jth packet is != -1 then we can either use that packet or we can neglect it and go to the j-1th packet thus : func(i,j,count) = min{ (func(i-j, j-1, count+1), func(i,j-1, count) } 3- If the value = 0 i.e. the packet is free. then again we might either use it or skip it like in case of step 2. so the recurrence: func(i,j,count) = min{ (func(i-j, j-1, count), func(i,j-1, count) }. No count+1 here as the packet is free so are not going to buy it. Hope this will help in better understanding the logic! -- 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.
[algogeeks] SPOJ- MPILOT WA on 10th TEST FILE
I have been trying to solve this problem using DP. i managed to realize the problem in the form of recurrence.. The solution is: Suppose the task was : given N pilots you have to assign N/2 of them as captains and N/2 as assistances. Furthermore you need to do this in a way such that for every 1=X=N, the group of the youngest X pilots doesn't contain more captains than assistances. And you want to do all this in the cheapest way possible (every pilot has an captain_salary[] and an assistant_salary[] value and the cost is computed as in the original problem). So let f(c,m) be the best we can do given that we already assigned the roles to the first c-1 pilots and currently there are m more assistances than there are captains. It is now true that (except for boundary cases) that f(c,m) = min (f(c+1,m-1)+captain_salary[c],f(c+1,m+1)+ assistant_salary[c]). Here's my code: http://ideone.com/M5b9da I'm getting WA on 10th case again and again. Please help! Is there some other approach as well?? -- 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.
Re: [algogeeks] SPOJ- MPILOT WA on 10th TEST FILE
Could you post the test case you failed? Then we can have a check. 2013/5/12 Piyush Raman piyush2011...@gmail.com I have been trying to solve this problem using DP. i managed to realize the problem in the form of recurrence.. The solution is: Suppose the task was : given N pilots you have to assign N/2 of them as captains and N/2 as assistances. Furthermore you need to do this in a way such that for every 1=X=N, the group of the youngest X pilots doesn't contain more captains than assistances. And you want to do all this in the cheapest way possible (every pilot has an captain_salary[] and an assistant_salary[] value and the cost is computed as in the original problem). So let f(c,m) be the best we can do given that we already assigned the roles to the first c-1 pilots and currently there are m more assistances than there are captains. It is now true that (except for boundary cases) that f(c,m) = min (f(c+1,m-1)+captain_salary[c],f(c+1,m+1)+ assistant_salary[c]). Here's my code: http://ideone.com/M5b9da I'm getting WA on 10th case again and again. Please help! Is there some other approach as well?? -- 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. -- 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.
Re: [algogeeks] SPOJ- MPILOT WA on 10th TEST FILE
The test cases are not public. Gonna have to find the bug in the logic! Here's the link of the problem statement: http://www.spoj.com/problems/MPILOT/ On Mon, May 13, 2013 at 1:36 AM, Tian Guo tian@epfl.ch wrote: Could you post the test case you failed? Then we can have a check. 2013/5/12 Piyush Raman piyush2011...@gmail.com I have been trying to solve this problem using DP. i managed to realize the problem in the form of recurrence.. The solution is: Suppose the task was : given N pilots you have to assign N/2 of them as captains and N/2 as assistances. Furthermore you need to do this in a way such that for every 1=X=N, the group of the youngest X pilots doesn't contain more captains than assistances. And you want to do all this in the cheapest way possible (every pilot has an captain_salary[] and an assistant_salary[] value and the cost is computed as in the original problem). So let f(c,m) be the best we can do given that we already assigned the roles to the first c-1 pilots and currently there are m more assistances than there are captains. It is now true that (except for boundary cases) that f(c,m) = min (f(c+1,m-1)+captain_salary[c],f(c+1,m+1)+ assistant_salary[c]). Here's my code: http://ideone.com/M5b9da I'm getting WA on 10th case again and again. Please help! Is there some other approach as well?? -- 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. -- 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. -- 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.
Re: [algogeeks] SPOJ- MPILOT WA on 10th TEST FILE
Great! Thanks! I think one possible problem is that for f[c][m], the range of m should bem= [0, min(c/2, n/2)] In your code, m is only related to n/2. 2013/5/12 Piyush Raman piyush2011...@gmail.com The test cases are not public. Gonna have to find the bug in the logic! Here's the link of the problem statement: http://www.spoj.com/problems/MPILOT/ On Mon, May 13, 2013 at 1:36 AM, Tian Guo tian@epfl.ch wrote: Could you post the test case you failed? Then we can have a check. 2013/5/12 Piyush Raman piyush2011...@gmail.com I have been trying to solve this problem using DP. i managed to realize the problem in the form of recurrence.. The solution is: Suppose the task was : given N pilots you have to assign N/2 of them as captains and N/2 as assistances. Furthermore you need to do this in a way such that for every 1=X=N, the group of the youngest X pilots doesn't contain more captains than assistances. And you want to do all this in the cheapest way possible (every pilot has an captain_salary[] and an assistant_salary[] value and the cost is computed as in the original problem). So let f(c,m) be the best we can do given that we already assigned the roles to the first c-1 pilots and currently there are m more assistances than there are captains. It is now true that (except for boundary cases) that f(c,m) = min (f(c+1,m-1)+captain_salary[c],f(c+1,m+1)+ assistant_salary[c]). Here's my code: http://ideone.com/M5b9da I'm getting WA on 10th case again and again. Please help! Is there some other approach as well?? -- 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. -- 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. -- 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. -- 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.
[algogeeks] SPOJ-NWERC11A TLE
http://www.spoj.com/problems/NWERC11A/ I have been trying to solve this problem but am getting TLE for larger inputs. Can't come up with an optimal approach!! --
Re: [algogeeks] spoj problem EASYMATH
Using KISS :) http://en.wikipedia.org/wiki/KISS_principle Ps: is not an offensive message Wladimir Araujo Tavares *Federal University of Ceará http://lia.ufc.br/%7Ewladimir/ Homepage http://lia.ufc.br/%7Ewladimir/ | Maratonahttps://sites.google.com/site/quixadamaratona/| * On Fri, Sep 28, 2012 at 6:17 PM, icy` vipe...@gmail.com wrote: why not just brute force this? one little array contains [a, (a+d), (a+2d), (a+3d), (a+4d) ], which is then filtered so that none of those are multiples of another. Then set a count variable to m-n+1. Check all numbers in range against your little array, decrementing count and breaking out if a divisible num is found. In Ruby, screenshot so that syntax highlighting remains. (comments start with # ) [image: Inline image 1] -- 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. image.png
Re: [algogeeks] spoj problem EASYMATH
@Wladimir : you have to use formula given in below link http://en.wikipedia.org/wiki/Inclusion%E2%80%93exclusion_principle On Fri, Sep 28, 2012 at 12:26 AM, Wladimir Tavares wladimir...@gmail.comwrote: what happens when a = 3, d = 5 a, a + d, d +2, a +3 d = 3,8,13,18? Wladimir Araujo Tavares *Federal University of Ceará http://lia.ufc.br/%7Ewladimir/ Homepage http://lia.ufc.br/%7Ewladimir/ | Maratonahttps://sites.google.com/site/quixadamaratona/| * On Thu, Sep 27, 2012 at 8:57 AM, atul anand atul.87fri...@gmail.comwrote: @ashish : here is the generalized equation http://en.wikipedia.org/wiki/Inclusion%E2%80%93exclusion_principle note : you need to take LCM of a,a+d,a+2d etc etcwhenever you are dividing to find count On Thu, Sep 27, 2012 at 2:55 AM, ashish pant asheesh...@gmail.comwrote: thanks for your reply.. actually i was thinking the same thing.. but I am facing problems in finding the unique multiples of a+3d and a+4d as applying inclusion exclusion principle in this way is getting too difficult due to large no of factors to be added and subtracted.. is der any other approach or any way to simplify the process.. -- 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] spoj problem EASYMATH
why not just brute force this? one little array contains [a, (a+d), (a+2d), (a+3d), (a+4d) ], which is then filtered so that none of those are multiples of another. Then set a count variable to m-n+1. Check all numbers in range against your little array, decrementing count and breaking out if a divisible num is found. In Ruby, screenshot so that syntax highlighting remains. (comments start with # ) [image: Inline image 1] -- 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. image.png
Re: [algogeeks] spoj problem EASYMATH
thanks for your reply.. actually i was thinking the same thing.. but I am facing problems in finding the unique multiples of a+3d and a+4d as applying inclusion exclusion principle in this way is getting too difficult due to large no of factors to be added and subtracted.. is der any other approach or any way to simplify the process.. -- 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 EASYMATH
@ashish : here is the generalized equation http://en.wikipedia.org/wiki/Inclusion%E2%80%93exclusion_principle note : you need to take LCM of a,a+d,a+2d etc etcwhenever you are dividing to find count On Thu, Sep 27, 2012 at 2:55 AM, ashish pant asheesh...@gmail.com wrote: thanks for your reply.. actually i was thinking the same thing.. but I am facing problems in finding the unique multiples of a+3d and a+4d as applying inclusion exclusion principle in this way is getting too difficult due to large no of factors to be added and subtracted.. is der any other approach or any way to simplify the process.. -- 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 EASYMATH
what happens when a = 3, d = 5 a, a + d, d +2, a +3 d = 3,8,13,18? Wladimir Araujo Tavares *Federal University of Ceará http://lia.ufc.br/%7Ewladimir/ Homepage http://lia.ufc.br/%7Ewladimir/ | Maratonahttps://sites.google.com/site/quixadamaratona/| * On Thu, Sep 27, 2012 at 8:57 AM, atul anand atul.87fri...@gmail.com wrote: @ashish : here is the generalized equation http://en.wikipedia.org/wiki/Inclusion%E2%80%93exclusion_principle note : you need to take LCM of a,a+d,a+2d etc etcwhenever you are dividing to find count On Thu, Sep 27, 2012 at 2:55 AM, ashish pant asheesh...@gmail.com wrote: thanks for your reply.. actually i was thinking the same thing.. but I am facing problems in finding the unique multiples of a+3d and a+4d as applying inclusion exclusion principle in this way is getting too difficult due to large no of factors to be added and subtracted.. is der any other approach or any way to simplify the process.. -- 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 EASYMATH
an idea of the approach would be enough.. plz help.. -- 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 problem EASYMATH
help needed in spoj problem EASYMATH http://spoj.pl/problems/EASYMATH.. i thought about inclusion exclusion principle but unable to get to a solution.. plz help.. -- 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/-/Zm2bwN2FHRQJ. 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 problem EASYMATH
please suggest something : Problem : http://www.spoj.pl/problems/EASYMATH/ C++ code : http://ideone.com/r2OSb was getting wrong ans due to over flow i think in LCM() for big prime's i guess. thin tried in python . Now getting NZEC for python code which mean's high level or recurrsion some where preventing normal termination . but where ?? Python code: http://ideone.com/KDPPJ -- 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 EASYMATH
use return (a/gcd(a,b)*b instead On Sun, Jun 24, 2012 at 7:10 PM, Sourabh Singh singhsourab...@gmail.comwrote: please suggest something : Problem : http://www.spoj.pl/problems/EASYMATH/ C++ code : http://ideone.com/r2OSb was getting wrong ans due to over flow i think in LCM() for big prime's i guess. thin tried in python . Now getting NZEC for python code which mean's high level or recurrsion some where preventing normal termination . but where ?? Python code: http://ideone.com/KDPPJ -- 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 EASYMATH
dont post codes, ask whether your algorithm is correct or not. On Sun, Jun 24, 2012 at 8:29 PM, Hassan Monfared hmonfa...@gmail.comwrote: use return (a/gcd(a,b)*b instead On Sun, Jun 24, 2012 at 7:10 PM, Sourabh Singh singhsourab...@gmail.comwrote: please suggest something : Problem : http://www.spoj.pl/problems/EASYMATH/ C++ code : http://ideone.com/r2OSb was getting wrong ans due to over flow i think in LCM() for big prime's i guess. thin tried in python . Now getting NZEC for python code which mean's high level or recurrsion some where preventing normal termination . but where ?? Python code: http://ideone.com/KDPPJ -- 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 :STAMPS
@MAYANK your output format is wrong.use printf(\nScenario #%d:\n,(i+1)); and if(sum sta) On Thu, Jun 21, 2012 at 12:34 PM, Mayank Singh singh13490may...@gmail.comwrote: here is my code /*#includestdio.h #includeconio.h int main() { int cand,sum; int T,N,i,j,temp[10]; scanf(%d,T); sum = 0; for(i=0;iT;i++) { scanf(%d,N); for(j=0;jN;j++) { scanf(%d,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; }*/ #includestdio.h #includestdlib.h int main() { int t,frd,i,j,arr[1],sum,k,arr1[10],p; scanf(%d,t); long int sta; for(i=0;it;i++) { scanf(%ld,sta); scanf(%d,frd); for(j=0;jfrd;j++) { scanf(%d,arr[j]); } for(j=0;jfrd;j++) { for(k=0;kfrd-1;k++) { if(arr[k]arr[k+1]) { sum = arr[k]; arr[k] = arr[k+1]; arr[k+1] = sum; } } } sum = 0; p=0; for(k=0;kfrd;k++) { if(sum = sta) { sum = sum+arr[k]; p++; } else break; } if(sum sta) arr1[i] = 0; else arr1[i] = p; } for(i=0;it;i++) { printf(\nScenario #%d\n:,(i+1)); if(arr1[i] == 0) printf(impossible\n); else printf(%d\n,arr1[i]); } return 0; } i am getting WA . plz help me... thanx -- 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. -- pardeep kumar -- 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 :STAMPS
use if(sum sta) instead of if(sum=sta) because in case sum==sta..your code will still increment p .but the value of p should not be incremented in this case.and in your output format colon : should be placed before \n to follow the format specified for the problem. On Fri, Jun 22, 2012 at 12:48 PM, Pradip Singh qnit...@gmail.com wrote: @MAYANK your output format is wrong.use printf(\nScenario #%d:\n,(i+1)); and if(sum sta) On Thu, Jun 21, 2012 at 12:34 PM, Mayank Singh singh13490may...@gmail.com wrote: here is my code /*#includestdio.h #includeconio.h int main() { int cand,sum; int T,N,i,j,temp[10]; scanf(%d,T); sum = 0; for(i=0;iT;i++) { scanf(%d,N); for(j=0;jN;j++) { scanf(%d,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; }*/ #includestdio.h #includestdlib.h int main() { int t,frd,i,j,arr[1],sum,k,arr1[10],p; scanf(%d,t); long int sta; for(i=0;it;i++) { scanf(%ld,sta); scanf(%d,frd); for(j=0;jfrd;j++) { scanf(%d,arr[j]); } for(j=0;jfrd;j++) { for(k=0;kfrd-1;k++) { if(arr[k]arr[k+1]) { sum = arr[k]; arr[k] = arr[k+1]; arr[k+1] = sum; } } } sum = 0; p=0; for(k=0;kfrd;k++) { if(sum = sta) { sum = sum+arr[k]; p++; } else break; } if(sum sta) arr1[i] = 0; else arr1[i] = p; } for(i=0;it;i++) { printf(\nScenario #%d\n:,(i+1)); if(arr1[i] == 0) printf(impossible\n); else printf(%d\n,arr1[i]); } return 0; } i am getting WA . plz help me... thanx -- 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. -- pardeep kumar -- pardeep kumar -- 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 : CANDY
in this prob also for i=0, i to k read cand rem=(rem+cand)%k if (rem) then no else yes -- 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 : CANDY
my code is running perfectly well but giving WA in spoj.. #includestdio.h #includestdlib.h int main() { int cand,sum; int T,N,i,j,temp[10]; scanf(%d,T); sum = 0; for(i=0;iT;i++) { scanf(%d,N); for(j=0;jN;j++) { scanf(%d,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; } -- 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 : CANDY
i think you should try to give output for each test case rather to use any temp array -- 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 problem : CANDY III
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.
Re: [algogeeks] SPOJ problem : CANDY III
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] SPOJ problem : CANDY III
@Mayank coding style not seems gud.. try this... int main() { int testCases; scanf(%d,testCases); while(testCases--0) { //perform ur logic //print output for each test case here instead of storing it into an array. } } return 0; } On Thu, Jun 21, 2012 at 10:35 PM, Mayank Singh singh13490may...@gmail.comwrote: thanx it worked -- 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. -- Thanks Regards Amritpal singh -- 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 question LITE
#includeiostream using namespace std; struct node { int num; int l,r; node * left; node * right; }; node * create(node * root,int start,int end); node * update(node * root, int i,int j); int query(node * root,int i,int j); main() { int n,q; cinnq; node * root=new node; root-num=0; root-left=NULL; root-right=NULL; root=create(root,0,n-1); while(q--) { int type,i,j; cintypeij; if(type==0) root=update(root,i,j); if(type==1) coutquery(root,i,j); } } node * create(node * root,int start,int end) { if(start==end) { node * temp=new node(); temp-num=0; temp-right=NULL; temp-left=NULL; temp-l=temp-r=start; return temp; } if(start!=end) { if(root==NULL) root=new node(); root-num=0; root-l=start; root-r=end; root-left=create(root-left,start,(start+end)/2); root-right=create(root-right,((start+end)/2)+1,end); return root; } } node * update(node * root,int i,int j) { if(root-l==root-r (root-l =iroot-r =j)) { root-num=1-(root-num); return root; } if(root-left) root-left=update(root-left,i,j); if(root-right) root-right=update(root-right,i,j); if(root-left root-right) root-num=root-left-num+root-right-num; return root; } int query(node * root,int i,int j) { if(root-l=i root-r=j) return root-num; int ans1,ans2; if(root-left) ans1=query(root-left,i,j); if(root-right) ans2=query(root-right,i,j); if(!root-left !root-right) return 0; return ans1+ans2; } this is my solution to http://www.spoj.pl/problems/LITE/ . But i am getting wrong answer. Can someone suggest a few test cases for which my solution might be failing ? -- 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/-/h6UQhCs1W_0J. 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 problem : CANDY
i am using long long but still getting WA. here's my code #includestdio.h #includeconio.h int main() { long long cand,sum; int T,N,i,j,temp[10]; scanf(%d,T); 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; } plz help me.. what's wrong in my code -- 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 : CANDY
long long not require in this que . try it again.. -- 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 : CANDY
still getting the WA . is there any test case i am getting wrong? -- 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 : CANDY
here is my code u can check that.. http://ideone.com/Gii1d -- 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 : CANDY
@mayank: For each testcase sum is not zero make sum=0 inside the for loop -- 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 : CANDY
oh i am really sorry the problem is CANDY III can you help me regarding that once again sorry -- 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 Problems SCUBADIV
Hi, I am trying to solve this problem. http://www.spoj.pl/problems/SCUBADIV/ But I am getting a lot of WAs! Any good logic(Solution) to solve the problem? Thanks in advance for your reply. Rituraj 2nd year B.Tech(CSE) NIT-Patna -- 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/-/16lWxB_BhlsJ. 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 problem : POKER
here is my code: #includestdio.h #includestring.h #includestdlib.h int main() { int t,i,j,k1,k2,ans[40],sum,sum1; char str[40][20],str1[6],str2[6]; scanf(%d,t); for(i=0;i=t;i++) { gets(str[i]); } for(i=1;i=t;i++) { for(j=1,k1=0;j15,k15;j=j+3,k1++) { str1[k1] = str[i][j]; } str1[5] = '\0'; for(j=0,k1=0;j15,k15;j=j+3,k1++) { str2[k1] = str[i][j]; } str2[5] = '\0'; sum = 0; for(k1=0;k15;k1++) sum = sum+str2[k1]; if(strcmp(str1,H)==0 || strcmp(str1,C)==0 || strcmp(str1,S)==0 || strcmp(str1,D)==0) { if(sum=260 sum = 263 || sum == 271 || sum == 306 || sum == 326 || sum == 352 || sum == 371 || sum == 379) { if(sum == 379) ans[i] = 1; else ans[i] = 2; } else ans[i] = 3; } else { if(sum=260 sum = 263 || sum == 271 || sum == 306 || sum == 326 || sum == 352 || sum == 371 || sum == 379) ans[i] = 4; else { j = 0; for(k1=0;k15;k1++) { for(k2=k1+1;k25;k2++) //ASCII comparison of 4 of a kind gives 6 { sum = str2[k1]; sum1 = str2[k2]; if(sum == sum1) j++; } } switch(j) { case 1: ans[i] = 9; break; case 2: ans[i] = 8; break; case 3: ans[i] = 7; break; case 4: ans[i] = 6; break; case 6: ans[i] = 5; break; } } } } for(i=1;i=t;i++) { switch(ans[i]) { case 1: printf(royal flush\n); break; case 2: printf(straight flush\n); break; case 3: printf(flush\n); break; case 4: printf(straight\n); break; case 5: printf(four of a kind\n); break; case 6: printf(full house\n); break; case 7: printf(three of a kind\n); break; case 8: printf(two pairs\n); break; case 9: printf(pair\n); break; default: printf(high card\n); } } return 0; } it ran successfully but is giving WA in spoj.. 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.
[algogeeks] spoj problem : NSTEPS
here is my code for the above problem: #includestdio.h #includestdlib.h int main() { int i,x[1],y[1],val; long n; scanf(%d,n); for(i=0;in;i++) { scanf(%d,x[i]); scanf(%d,y[i]); } for(i=0;in;i++) { if(x[i] == y[i] x[i]%2 == 0) { val = x[i]+y[i]; printf(%d\n,val); } else if(x[i] == y[i] x[i]%2 != 0) { val = (x[i]+y[i])-1; printf(%d\n,val); } else if(x[i] != y[i] x[i]%2 == 0 (x[i]-y[i]) == 2) { val = (x[i]+y[i]); printf(%d\n,val); } else if(x[i] != y[i] x[i]%2 != 0 (x[i]-y[i]) == 2) { val = (x[i]+y[i])-1; printf(%d\n,val); } else printf(No Number\n); } return 0; } i am getting WA . plz help me regarding 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] spoj problem : NSTEPS
array size not sufficient coz n can be greater than 1 try x[100], y[100] :-) On Sun, Jun 17, 2012 at 9:32 PM, Mayank Singh singh13490may...@gmail.com wrote: here is my code for the above problem: #includestdio.h #includestdlib.h int main() { int i,x[1],y[1],val; long n; scanf(%d,n); for(i=0;in;i++) { scanf(%d,x[i]); scanf(%d,y[i]); } for(i=0;in;i++) { if(x[i] == y[i] x[i]%2 == 0) { val = x[i]+y[i]; printf(%d\n,val); } else if(x[i] == y[i] x[i]%2 != 0) { val = (x[i]+y[i])-1; printf(%d\n,val); } else if(x[i] != y[i] x[i]%2 == 0 (x[i]-y[i]) == 2) { val = (x[i]+y[i]); printf(%d\n,val); } else if(x[i] != y[i] x[i]%2 != 0 (x[i]-y[i]) == 2) { val = (x[i]+y[i])-1; printf(%d\n,val); } else printf(No Number\n); } return 0; } i am getting WA . plz help me regarding 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. -- -- 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 problem
plz nyone explain how to approach this problem.. http://www.spoj.pl/problems/XORROUND/ -- 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
@ashish pant We must compute all the queries in O(n)+O(k). We must have array like counting array. It is not my logic but my friend told about this logic -- 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
in 1 2 3 4 5 6...o/p ll b 5 -- 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/-/eWlM2oyysowJ. 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
not abe to get solution On Mon, Feb 13, 2012 at 10:49 AM, atul anand atul.87fri...@gmail.comwrote: what problem are you facing ...??? On Thu, Feb 9, 2012 at 12:01 PM, UTKARSH SRIVASTAV usrivastav...@gmail.com wrote: I have been doing this question for a time but was not able to solve it. It is based josephus problem ? Has anybody any idea http://www.spoj.pl/problems/WTK/ -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @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. -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @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.
Re: [algogeeks] spoj
what will the output of following input: 1) 1 2 3 4 5 6 2) 1 2 3 4 5 6 7 i am bit confused.because in the given link for input 2 ...output is 2but it should be written in this foam 2 1... because 1 stands right of 2 so output should be 1... On Mon, Feb 13, 2012 at 1:41 PM, UTKARSH SRIVASTAV usrivastav...@gmail.comwrote: not abe to get solution On Mon, Feb 13, 2012 at 10:49 AM, atul anand atul.87fri...@gmail.comwrote: what problem are you facing ...??? On Thu, Feb 9, 2012 at 12:01 PM, UTKARSH SRIVASTAV usrivastav...@gmail.com wrote: I have been doing this question for a time but was not able to solve it. It is based josephus problem ? Has anybody any idea http://www.spoj.pl/problems/WTK/ -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @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. -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @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] spoj
what problem are you facing ...??? On Thu, Feb 9, 2012 at 12:01 PM, UTKARSH SRIVASTAV usrivastav...@gmail.comwrote: I have been doing this question for a time but was not able to solve it. It is based josephus problem ? Has anybody any idea http://www.spoj.pl/problems/WTK/ -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @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.
[algogeeks] Spoj Domino Tiling
I am solving spoj problem Tiling a Grid With Dominoes.(http://www.spoj.pl/problems/GNY07H/).. I am not able to come up with a recurrence relation.. One of my friend said it has the recurrence relation as f(n) = f(n-1) + 5*f(n-2) + f(n-3) - f(n-4). I am not convinced and have trouble deriving this formula from given data..Can somebody help?? -- 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 Domino Tiling
well i have used three recurrences :P formed them by following a traditional approach f[i] = f[i-1] + 2*g[i-1] + h[i-1] + f[i-2]; g[i] = f[i-1] + g[i-1]; h[i] = f[i-1] + h[i-2]; On Thu, Feb 9, 2012 at 7:19 PM, Kunal Patil kp101...@gmail.com wrote: I am solving spoj problem Tiling a Grid With Dominoes.(http://www.spoj.pl/problems/GNY07H/).. I am not able to come up with a recurrence relation.. One of my friend said it has the recurrence relation as f(n) = f(n-1) + 5*f(n-2) + f(n-3) - f(n-4). I am not convinced and have trouble deriving this formula from given data..Can somebody help?? -- 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
I have been doing this question for a time but was not able to solve it. It is based josephus problem ? Has anybody any idea http://www.spoj.pl/problems/WTK/ -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @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.
[algogeeks] Spoj ABCPATH
Hi all I was doing this problem on spoj and it is running correctly on my system and ideone. But when I submit it, it gives me SIGSEGV. Even after 2 days research I am unable to find the cause. Please help!!! The code is http://ideone.com/8aZLM PS- If it shows correct answer on your system also, try submitting it. -- 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
No one is going to check my your code Don't submit my code directly to spoj ,,,Learn from it...and then make your own code.. #includeiostream #includevector #includeset #includemap #includequeue #includestack #includestring #includealgorithm #includefunctional #includeiomanip #includecstdio #includecmath #includecstring #includecstdlib #includecassert using namespace std; /* int size=visited.size(); coutsizeendl; for(j=0;isize;j++) { if(visited[w[i][j]]=visited[i]) { return 1; } else if(!visited[w[i][j]]) { Q.push(w[i][j]); if(visited[i]==1) visited[w[i][j]]=2; else visited[w[i][j]]=1; } } */ int bfs(vectorvectorint w ,vectorint visited,int start_vertex) { int i,j; queueint Q; Q.push(start_vertex); visited[start_vertex] =1; while(!Q.empty()) { int i = Q.front(); // get the tail element from queue Q.pop(); vectorint::iterator it; for(it=w[i].begin();it!=w[i].end();it++) { //pushing neighbouring nodes of current nodes if(visited[*it]==visited[i]) return 1; else if(!visited[*it]) { Q.push(*it); if(visited[i]==1) visited[*it]=2; else visited[*it]=1; } } } return 0; } /* Main code starts from here */ int main() { int i,j,a,b,N,tc; int k,check=0; scanf(%d,tc); int p=1; while(tc--) { scanf(%d%d,N,k); if(N==0) return 0; vectorvectorint w(N,vectorint(0)); for(i=0;ik;i++) { scanf(%d%d,a,b); w[a-1].push_back(b-1);//v[a-1][j]=b-1 w[b-1].push_back(a-1); } vectorint visit(N,0); for(i=0;iN;i++) { if(!visit[i]) { check=bfs(w,visit,i); if(check==1) { printf(Scenario #%d:\nSuspicious bugs found!\n,p); p++; break; } } } if(check==0) { printf(Scenario #%d:\nNo suspicious bugs found!\n,p); p++; } } return 0; } On Mon, Jan 23, 2012 at 2:57 PM, D!leep Gupta dileep.smil...@gmail.comwrote: guys plz help... http://www.spoj.pl/problems/BUGLIFE/ i m getting wrong ans can any one give me the test case on which my code giving wrong... i m unable to find out #includestdio.h#define MAX 2500int front=-1;int rear=-1;int q[MAX]; void addq(int n) { q[++rear]=n; }int delq() { if(front==rear) return -1; else return q[++front]; } int main(){int t,k=0;int num,action,m,n;int i,j;scanf http://www.opengroup.org/onlinepubs/009695399/functions/scanf.html(%d,t);while(t--) { k++; front=-1; rear=-1; int error=0; int visit[MAX]={0}; visit[0]=1; scanf http://www.opengroup.org/onlinepubs/009695399/functions/scanf.html(%d%d,num,action); int n=num; int arr[num][num],a[num]; for(i=0;inum;i++) { a[i]=-2; for(j=0;jnum;j++) arr[i][j]=0; } while(action--) { scanf http://www.opengroup.org/onlinepubs/009695399/functions/scanf.html(%d%d,m,n); arr[m-1][n-1]=arr[n-1][m-1]=1; } int l; addq(0); while(n--) { if((i=delq())==-1) {for(l=0;lnum;l++) if(a[l]==-2) { addq(l); n++; visit[l]=1; break; } } else { a[i]=i; for(j=i+1;jnum;j++) { if(arr[i][j] i!=j)
Re: [algogeeks] spoj problem:Street parade
@Anshul AGARWAL Input : 4 2 1 3 4 Expected Output : Yes Your's Code Output : No On 12/20/11, sunny agrawal sunny816.i...@gmail.com wrote: @ Anshul it will be nice if you post your logic rather than Code, and also Code posting without logic and comments is not allowed in the group. i don't know who approved this post but take care of this from next time. On Tue, Dec 20, 2011 at 7:41 PM, Anshul AGARWAL anshul.agarwa...@gmail.com wrote: problem:street parade: http://www.spoj.pl/problems/STPAR/ my code give correct answer for all test case that i run but still it give WA. plz provide me more test cases . my code is #includestdio.h #includeiostream #includealgorithm using namespace std; int main() { int n,a[1010],b[1010],s[1010],t=0,q=1; scanf(%d,n);//2 1 4 3 while(n) { int i=0,f=0,j=0; q=1;t=0;s[0]=11; for(i=0;in;i++) { scanf(%d,a[i]); b[i]=a[i]; } sort(a,a+n); for(i=0;in;i++) { if(i(n-1)a[i]==a[i+1]) { f=1;break;} if(s[t]==a[j]) { j++; t--; } else if(b[i]==a[j]) { j++; } else { if(s[t]==a[j]) { j++; t--; if(t==0) s[0]=11; } else if(s[t]b[i]) { f=1; break; } else { if(t==0s[0]==11) { s[t]=b[i]; }else { t=t+1; s[t]=b[i]; } } } } while(t=0s[0]!=11) { if(s[t]==a[j]) { t--; if(t==0) s[0]=11; j++; } else { f=1; break; } } if(f==1) printf(no\n); else { printf(yes\n); } scanf(%d,n); } } Thanx in advance Anshul Agarwal Nit Allahabad Computer Science -- 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. -- - Sharad Dixit B.Tech(IT) Indian Institute of Information Technology, Allahabad 3rd year -- 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:Street parade
Thanx Sharad finally got AC *Anshul Agarwal Nit Allahabad Computer Science** * On Tue, Dec 20, 2011 at 3:16 PM, sharad dixit sharad.emine...@gmail.comwrote: @Anshul AGARWAL Input : 4 2 1 3 4 Expected Output : Yes Your's Code Output : No On 12/20/11, sunny agrawal sunny816.i...@gmail.com wrote: @ Anshul it will be nice if you post your logic rather than Code, and also Code posting without logic and comments is not allowed in the group. i don't know who approved this post but take care of this from next time. On Tue, Dec 20, 2011 at 7:41 PM, Anshul AGARWAL anshul.agarwa...@gmail.com wrote: problem:street parade: http://www.spoj.pl/problems/STPAR/ my code give correct answer for all test case that i run but still it give WA. plz provide me more test cases . my code is #includestdio.h #includeiostream #includealgorithm using namespace std; int main() { int n,a[1010],b[1010],s[1010],t=0,q=1; scanf(%d,n);//2 1 4 3 while(n) { int i=0,f=0,j=0; q=1;t=0;s[0]=11; for(i=0;in;i++) { scanf(%d,a[i]); b[i]=a[i]; } sort(a,a+n); for(i=0;in;i++) { if(i(n-1)a[i]==a[i+1]) { f=1;break;} if(s[t]==a[j]) { j++; t--; } else if(b[i]==a[j]) { j++; } else { if(s[t]==a[j]) { j++; t--; if(t==0) s[0]=11; } else if(s[t]b[i]) { f=1; break; } else { if(t==0s[0]==11) { s[t]=b[i]; }else { t=t+1; s[t]=b[i]; } } } } while(t=0s[0]!=11) { if(s[t]==a[j]) { t--; if(t==0) s[0]=11; j++; } else { f=1; break; } } if(f==1) printf(no\n); else { printf(yes\n); } scanf(%d,n); } } Thanx in advance Anshul Agarwal Nit Allahabad Computer Science -- 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. -- - Sharad Dixit B.Tech(IT) Indian Institute of Information Technology, Allahabad 3rd year -- 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
[algogeeks] SPOJ TLE
I am getting a lot of tle's for this problem. https://www.spoj.pl/problems/BUGLIFE/ Here is my code #includeiostream #includecstdio #includecstring using namespace std; int g[2001][2001]; int color[2001]; short stack[5001]; int bugs, rel; int inline complement(int n); bool inline dfs(); int v1, v2; int main() { int cases; scanf(%d, cases); for(int i=1; i=cases; i++) { scanf(%d %d, bugs, rel); memset(g, 0x00, sizeof g); int relq = rel; while(relq--) { scanf(%d %d, v1, v2); g[v1][++g[v1][0]]=v2; g[v2][++g[v2][0]]=v1; } printf(Scenario #%d:\n, i); if(dfs()) { printf(No suspicious bugs found!\n); } else { printf(Suspicious bugs found!\n); } } return 0; } int inline complement(int n) { if(n==1) return 2; if(n==2) return 1; } bool inline dfs() //iterative DFS { int node, no, in; memset(color, 0x00, (bugs+1)*sizeof(int)); stack[0]=0; for(int it = 1; it=bugs; it++) { if(color[(it)]==0 g[(it)][0]!=0) { stack[++stack[0]]=(it); color[(it)] = 1; while(stack[0] (rel0)) //if stack is not empty { in = stack[stack[0]--]; no = g[in][0]; for(int j=1; j=no; j++) { node = g[in][j]; if(color[node]!=0) { if(color[node] == color[in]) { return false; } } else { color[node] = complement(color[in]); stack[++stack[0]]=node; rel--; } } } } } return true; } Please help me. Ashok -- 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 problem
problem is http://www.spoj.pl/problems/ELEVTRBL/ and my solution is give wrong answer on spoj . Plz help me to find in which case my solution give wrong answer. * #includeiostream ** #includestdio.h using namespace std; int main() { long long int f,s,u,d,g,c,p; scanf(%lld%lld%lld%lld%lld,f,s,g,u,d); p=0; if(s==g) printf(0\n); if(sgu==0d!=0) { int temp=s-g; if((temp/d)*d==temp) { p=temp/d; printf(%lld\n,p); } else printf(use the stairs\n); } else if(sg) { int temp =s; s=g; g=temp; // cout2endl; } //cout1endl; c=s; if(sg) { while(1) { int temp=g-c; int q; if(u==0) { if(c==g) { printf(0\n); break; } else { printf(use the stairs\n); break; } } if(temp/u==(temp/u)*u) { q=temp/u; } else q=temp/u+1; if((c+q*u)=f) { // cout1endl; p=p+q; c=(q)*u+c; //coutcendl; } else {//cout2endl; p=p+temp/u; c=(temp/u)*u+c; } if(c==g) { // cout3endl; printf(%lld,p); break; } if(u==d||d==0||((u%d==0)d!=0)||(d%u==0u!=0)) { printf(use the stairs\n); break;} if(c-d=0) { // cout4endl; c=c-d; p+=1; // coutcendl; } else { // cout5endl; printf(use the stairs\n); break; } } } } Anshul Agarwal Nit Allahabad Computer Science** * -- 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
what;s your algorithm ? On Mon, Nov 14, 2011 at 7:57 PM, Anshul AGARWAL anshul.agarwa...@gmail.comwrote: problem is http://www.spoj.pl/problems/ELEVTRBL/ and my solution is give wrong answer on spoj . Plz help me to find in which case my solution give wrong answer. * #includeiostream ** #includestdio.h using namespace std; int main() { long long int f,s,u,d,g,c,p; scanf(%lld%lld%lld%lld%lld,f,s,g,u,d); p=0; if(s==g) printf(0\n); if(sgu==0d!=0) { int temp=s-g; if((temp/d)*d==temp) { p=temp/d; printf(%lld\n,p); } else printf(use the stairs\n); } else if(sg) { int temp =s; s=g; g=temp; // cout2endl; } //cout1endl; c=s; if(sg) { while(1) { int temp=g-c; int q; if(u==0) { if(c==g) { printf(0\n); break; } else { printf(use the stairs\n); break; } } if(temp/u==(temp/u)*u) { q=temp/u; } else q=temp/u+1; if((c+q*u)=f) { // cout1endl; p=p+q; c=(q)*u+c; //coutcendl; } else {//cout2endl; p=p+temp/u; c=(temp/u)*u+c; } if(c==g) { // cout3endl; printf(%lld,p); break; } if(u==d||d==0||((u%d==0)d!=0)||(d%u==0u!=0)) { printf(use the stairs\n); break;} if(c-d=0) { // cout4endl; c=c-d; p+=1; // coutcendl; } else { // cout5endl; printf(use the stairs\n); break; } } } } Anshul Agarwal Nit Allahabad Computer Science** * -- 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
i m try to increase current floor c by push up button until it equal or greater than g and increase co-responding push p.when my current floor is greater than g.i push down button once and increase p by 1. repeat this loop until i get c==g. *Anshul Agarwal Nit Allahabad Computer Science** * On Mon, Nov 14, 2011 at 9:50 AM, shady sinv...@gmail.com wrote: what;s your algorithm ? On Mon, Nov 14, 2011 at 7:57 PM, Anshul AGARWAL anshul.agarwa...@gmail.com wrote: problem is http://www.spoj.pl/problems/ELEVTRBL/ and my solution is give wrong answer on spoj . Plz help me to find in which case my solution give wrong answer. * #includeiostream ** #includestdio.h using namespace std; int main() { long long int f,s,u,d,g,c,p; scanf(%lld%lld%lld%lld%lld,f,s,g,u,d); p=0; if(s==g) printf(0\n); if(sgu==0d!=0) { int temp=s-g; if((temp/d)*d==temp) { p=temp/d; printf(%lld\n,p); } else printf(use the stairs\n); } else if(sg) { int temp =s; s=g; g=temp; // cout2endl; } //cout1endl; c=s; if(sg) { while(1) { int temp=g-c; int q; if(u==0) { if(c==g) { printf(0\n); break; } else { printf(use the stairs\n); break; } } if(temp/u==(temp/u)*u) { q=temp/u; } else q=temp/u+1; if((c+q*u)=f) { // cout1endl; p=p+q; c=(q)*u+c; //coutcendl; } else {//cout2endl; p=p+temp/u; c=(temp/u)*u+c; } if(c==g) { // cout3endl; printf(%lld,p); break; } if(u==d||d==0||((u%d==0)d!=0)||(d%u==0u!=0)) { printf(use the stairs\n); break;} if(c-d=0) { // cout4endl; c=c-d; p+=1; // coutcendl; } else { // cout5endl; printf(use the stairs\n); break; } } } } Anshul Agarwal Nit Allahabad Computer Science** * -- 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
one solution is use BFS On Mon, Nov 14, 2011 at 8:52 PM, Anshul AGARWAL anshul.agarwa...@gmail.com wrote: i m try to increase current floor c by push up button until it equal or greater than g and increase co-responding push p.when my current floor is greater than g.i push down button once and increase p by 1. repeat this loop until i get c==g. Anshul Agarwal Nit Allahabad Computer Science On Mon, Nov 14, 2011 at 9:50 AM, shady sinv...@gmail.com wrote: what;s your algorithm ? On Mon, Nov 14, 2011 at 7:57 PM, Anshul AGARWAL anshul.agarwa...@gmail.com wrote: problem is http://www.spoj.pl/problems/ELEVTRBL/ and my solution is give wrong answer on spoj . Plz help me to find in which case my solution give wrong answer. #includeiostream #includestdio.h using namespace std; int main() { long long int f,s,u,d,g,c,p; scanf(%lld%lld%lld%lld%lld,f,s,g,u,d); p=0; if(s==g) printf(0\n); if(sgu==0d!=0) { int temp=s-g; if((temp/d)*d==temp) { p=temp/d; printf(%lld\n,p); } else printf(use the stairs\n); } else if(sg) { int temp =s; s=g; g=temp; // cout2endl; } //cout1endl; c=s; if(sg) { while(1) { int temp=g-c; int q; if(u==0) { if(c==g) { printf(0\n); break; } else { printf(use the stairs\n); break; } } if(temp/u==(temp/u)*u) { q=temp/u; } else q=temp/u+1; if((c+q*u)=f) { // cout1endl; p=p+q; c=(q)*u+c; //coutcendl; } else {//cout2endl; p=p+temp/u; c=(temp/u)*u+c; } if(c==g) { // cout3endl; printf(%lld,p); break; } if(u==d||d==0||((u%d==0)d!=0)||(d%u==0u!=0)) { printf(use the stairs\n); break;} if(c-d=0) { // cout4endl; c=c-d; p+=1; // coutcendl; } else { // cout5endl; printf(use the stairs\n); break; } } } } Anshul Agarwal Nit Allahabad Computer Science -- 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. -- 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.
Re: [algogeeks] [SPOJ] ZSUM
Can you tell why (x * z * z) % MOD is different from (x * ( (z*z)%MOD) ) % MOD Again why ((x%MOD)*(z%MOD)*(z%MOD))%MOD is giving WA I thought of a simple examples like (100* 53*72) % 90 -- ((90+10)*53*72) % 90 -- (10*53*72)% 90 which is same as (100%90 * 53%90 * 72%90) % 90 Another example (100*91*92)%90 -- ( (90+10)*(90+1)*(90+2) ) % 90 -- 10 * 1 * 2 which is again same as (100%90 * 91%90 * 92%90) % 90 Are results different because of range overflow in case of bigger z ??? I'm weak at modular mathematics [?] So please help !! On Thu, Oct 20, 2011 at 11:48 AM, Wasif Hossain wasifhossain@gmail.comwrote: Just a MINOR change. please change the RED line(I've marked it below) in your code by the following line: *return (x*((z*z)%MOD))%MOD;* and enjoy an *ACCEPTED *verdict.* * *Wasif Hossain** * B.Sc. Student of Final Semester, Computer Science and Engineering(CSE), Bangladesh University of Engineering and Technology(BUET), Dhaka-1000 Bangladesh. On Thu, Oct 6, 2011 at 1:13 AM, hashd kirandandupr...@gmail.com wrote: I'm getting WA on the question : ZSUM-SPOJhttps://www.spoj.pl/problems/ZSUM/ Here is my code: Let me know if you can find the problem with the code #includecstdio #define MOD 1007 typedef unsigned long long u64; using namespace std; u64 modExp(u64 x, u64 y){ if(x==0) return 0; if(y==0) return 1; u64 z = modExp(x,y/2); if(y%2==0) return (z*z)%MOD; else *return (x*z*z)%MOD;* } int main(){ u64 n, k; scanf(%llu%llu,n,k); while(nk){ u64 ans = 0; if(n0) ans = (2*modExp(n-1,k) + modExp(n,k) + 2*modExp(n-1,n-1) + modExp(n,n))%MOD; printf(%llu\n,ans); scanf(%llu%llu,n,k); } return 0; } -- 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/-/p6j7nmaEUb4J. 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. 33D.gif
Re: [algogeeks] [SPOJ] ZSUM
As far as modular arithmetic is concerned, (x * z *z )%MOD = (x *(z *z)%MOD)%MOD = ((x%MOD)*(z%MOD)*(z%MOD))%MOD But when you try to calculate *(x * z * z)%MOD*, the intermediate result of* (x * z * z) *overflows the integer limit and hence gives the wrong result. similarly, intermediate value of *(x%MOD) * (y%MOD) * (z%MOD)* might also overflow the integer limit hence you are getting WA. On Tuesday, October 25, 2011, Kunal Patil wrote: Can you tell why (x * z * z) % MOD is different from (x * ( (z*z)%MOD) ) % MOD Again why ((x%MOD)*(z%MOD)*(z%MOD))%MOD is giving WA I thought of a simple examples like (100* 53*72) % 90 -- ((90+10)*53*72) % 90 -- (10*53*72)% 90 which is same as (100%90 * 53%90 * 72%90) % 90 Another example (100*91*92)%90 -- ( (90+10)*(90+1)*(90+2) ) % 90 -- 10 * 1 * 2 which is again same as (100%90 * 91%90 * 92%90) % 90 Are results different because of range overflow in case of bigger z ??? I'm weak at modular mathematics [?] So please help !! On Thu, Oct 20, 2011 at 11:48 AM, Wasif Hossain wasifhossain@gmail.com wrote: Just a MINOR change. please change the RED line(I've marked it below) in your code by the following line: *return (x*((z*z)%MOD))%MOD;* and enjoy an *ACCEPTED *verdict.* * *Wasif Hossain** * B.Sc. Student of Final Semester, Computer Science and Engineering(CSE), Bangladesh University of Engineering and Technology(BUET), Dhaka-1000 Bangladesh. On Thu, Oct 6, 2011 at 1:13 AM, hashd kirandandupr...@gmail.com wrote: I'm getting WA on the question : ZSUM-SPOJhttps://www.spoj.pl/problems/ZSUM/ Here is my code: Let me know if you can find the problem with the code #includecstdio #define MOD 1007 typedef unsigned long long u64; using namespace std; u64 modExp(u64 x, u64 y){ if(x==0) return 0; if(y==0) return 1; u64 z = modExp(x,y/2); if(y%2==0) return (z*z)%MOD; else *return (x*z*z)%MOD;* } int main(){ u64 n, k; scanf(%llu%llu,n,k); while(nk){ u64 ans = 0; if(n0) ans = (2*modExp(n-1,k) + modExp(n,k) + 2*modExp(n-1,n-1) + modExp(n,n))%MOD; printf(%llu\n,ans); scanf(%llu%llu,n,k); } return 0; } -- 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/-/p6j7nmaEUb4J. 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. 33D.gif
Re: [algogeeks] [SPOJ] ZSUM
Just a MINOR change. please change the RED line(I've marked it below) in your code by the following line: *return (x*((z*z)%MOD))%MOD;* and enjoy an *ACCEPTED *verdict.* * *Wasif Hossain** * B.Sc. Student of Final Semester, Computer Science and Engineering(CSE), Bangladesh University of Engineering and Technology(BUET), Dhaka-1000 Bangladesh. On Thu, Oct 6, 2011 at 1:13 AM, hashd kirandandupr...@gmail.com wrote: I'm getting WA on the question : ZSUM-SPOJhttps://www.spoj.pl/problems/ZSUM/ Here is my code: Let me know if you can find the problem with the code #includecstdio #define MOD 1007 typedef unsigned long long u64; using namespace std; u64 modExp(u64 x, u64 y){ if(x==0) return 0; if(y==0) return 1; u64 z = modExp(x,y/2); if(y%2==0) return (z*z)%MOD; else *return (x*z*z)%MOD;* } int main(){ u64 n, k; scanf(%llu%llu,n,k); while(nk){ u64 ans = 0; if(n0) ans = (2*modExp(n-1,k) + modExp(n,k) + 2*modExp(n-1,n-1) + modExp(n,n))%MOD; printf(%llu\n,ans); scanf(%llu%llu,n,k); } return 0; } -- 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/-/p6j7nmaEUb4J. 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] ZSUM
I'm getting WA on the question : ZSUM-SPOJhttps://www.spoj.pl/problems/ZSUM/ Here is my code: Let me know if you can find the problem with the code #includecstdio #define MOD 1007 typedef unsigned long long u64; using namespace std; u64 modExp(u64 x, u64 y){ if(x==0) return 0; if(y==0) return 1; u64 z = modExp(x,y/2); if(y%2==0) return (z*z)%MOD; else return (x*z*z)%MOD; } int main(){ u64 n, k; scanf(%llu%llu,n,k); while(nk){ u64 ans = 0; if(n0) ans = (2*modExp(n-1,k) + modExp(n,k) + 2*modExp(n-1,n-1) + modExp(n,n))%MOD; printf(%llu\n,ans); scanf(%llu%llu,n,k); } return 0; } -- 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/-/p6j7nmaEUb4J. 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 problem
http://www.spoj.pl/problems/POUR1/ hw the 2nd given test is correct. 2 3 4 first we fill 3 littre jar with water and put into 4 littre jar den again fill 3 littre and pour it in 2 littre remaining water in jar is 1 littre put it into 4 littre and we can measure 4 littre of water den why answer is -1...? -- 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 PIE
http://www.spoj.pl/problems/PIE/ I solved this using Binary Search its similar to shake shake shaky of spoj... but still get WA :( Plzz help... #includeiostream #includealgorithm using namespace std; bool solve(int *pie, int n, int mid,int f) { int sum = 0; for (int i=0; in; i++) sum += pie[i] / mid; if (sum = f) return true; else return false; } int binary_search(int *pie, int n, int f) { int low = 0, high = pie[n-1], mid; while (low high) { mid = low + (high - low + 1)/2; if (solve(pie, n, mid, f)) low = mid; else high = mid - 1; } return low; } int main() { //freopen(input.txt, r, stdin); //freopen(output.txt, w, stdout); const double pi = 3.14159265358979323846264338327950; int T; cin T; while (T--) { int n, f, pie[10001]; cin n f; for (int i=0; in; i++) { cin pie[i]; pie[i] *= pie[i]; } f++; sort(pie, pie + n); int largest = binary_search(pie, n, f); //cout largest is largest endl; double ans = largest * pi; printf(%.4lf\n, ans); } 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.
Re: [algogeeks] SPOJ PIE
One small observation, you can use the M_PI constant already available when you #include cmath On Thu, Sep 15, 2011 at 3:57 PM, KK kunalkapadi...@gmail.com wrote: http://www.spoj.pl/problems/PIE/ I solved this using Binary Search its similar to shake shake shaky of spoj... but still get WA :( Plzz help... #includeiostream #includealgorithm using namespace std; bool solve(int *pie, int n, int mid,int f) { int sum = 0; for (int i=0; in; i++) sum += pie[i] / mid; if (sum = f) return true; else return false; } int binary_search(int *pie, int n, int f) { int low = 0, high = pie[n-1], mid; while (low high) { mid = low + (high - low + 1)/2; if (solve(pie, n, mid, f)) low = mid; else high = mid - 1; } return low; } int main() { //freopen(input.txt, r, stdin); //freopen(output.txt, w, stdout); const double pi = 3.14159265358979323846264338327950; int T; cin T; while (T--) { int n, f, pie[10001]; cin n f; for (int i=0; in; i++) { cin pie[i]; pie[i] *= pie[i]; } f++; sort(pie, pie + n); int largest = binary_search(pie, n, f); //cout largest is largest endl; double ans = largest * pi; printf(%.4lf\n, ans); } 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. -- Gaurav Menghani -- 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
I am getting WA in this problem, I am not getting what i am doing wrong . http://www.spoj.pl/problems/AE2A/ My dp is: dp[n][k] = (dp[n - 1][k - 1] + dp[n - 1][k - 2] + dp[n - 1][k - 3] + dp[n - 1][k - 4] + dp[n - 1][k - 5] + dp[n - 1][k - 6]) and my code: #includeiostream using namespace std; int solve(int n, int k) { int** dp; dp = (int **)malloc(2*sizeof(int*)); dp[0]=(int*)malloc(111*sizeof(int)); dp[1]=(int*)malloc(111*sizeof(int)); for(int i=1;i=6;i++) dp[0][i]=1; int throws=n; n--; int sum=0; while(n--) { for(int i=1;i=k;i++) { dp[1][i]=0; sum=0; for(int j=1;j=6;j++) { if((i-j)0) break; sum+=dp[0][i-j]; } dp[1][i]=sum; } for(int i=1;i=k;i++) dp[0][i]=dp[1][i]; } dp[0][k]*=100; for(int i=0;ithrows;i++) dp[0][k]/=6; return dp[0][k]; } int main() { int cases; cincases; while(cases--) { long n,k; cinnk; coutsolve(n,k)endl; } 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.
Re: [algogeeks] SPOJ
Description of the problem and your solution could help others. On Wed, Sep 7, 2011 at 12:01 AM, Akshata Sharma akshatasharm...@gmail.com wrote: I am getting WA in this problem, I am not getting what i am doing wrong . http://www.spoj.pl/problems/AE2A/ My dp is: dp[n][k] = (dp[n - 1][k - 1] + dp[n - 1][k - 2] + dp[n - 1][k - 3] + dp[n - 1][k - 4] + dp[n - 1][k - 5] + dp[n - 1][k - 6]) and my code: #includeiostream using namespace std; int solve(int n, int k) { int** dp; dp = (int **)malloc(2*sizeof(int*)); dp[0]=(int*)malloc(111*sizeof(int)); dp[1]=(int*)malloc(111*sizeof(int)); for(int i=1;i=6;i++) dp[0][i]=1; int throws=n; n--; int sum=0; while(n--) { for(int i=1;i=k;i++) { dp[1][i]=0; sum=0; for(int j=1;j=6;j++) { if((i-j)0) break; sum+=dp[0][i-j]; } dp[1][i]=sum; } for(int i=1;i=k;i++) dp[0][i]=dp[1][i]; } dp[0][k]*=100; for(int i=0;ithrows;i++) dp[0][k]/=6; return dp[0][k]; } int main() { int cases; cincases; while(cases--) { long n,k; cinnk; coutsolve(n,k)endl; } 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. -- Gaurav Menghani -- 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
@rahul, yes i agree with what you said, but I don't think that this is causing WA here.. Its equivalent as if u take 2 1-darrays.. right? On Wed, Sep 7, 2011 at 8:25 AM, rahul vatsa vatsa.ra...@gmail.com wrote: if you are allocating memory for a n-d array, u shouldn't allocate memory for each row separately, wen u do that u get separate chunk of memory for each row, nd it breaks the basic rule of an array (i.e. array elements should be in contigious memory locations). On Tue, Sep 6, 2011 at 2:31 PM, Akshata Sharma akshatasharm...@gmail.comwrote: I am getting WA in this problem, I am not getting what i am doing wrong . http://www.spoj.pl/problems/AE2A/ My dp is: dp[n][k] = (dp[n - 1][k - 1] + dp[n - 1][k - 2] + dp[n - 1][k - 3] + dp[n - 1][k - 4] + dp[n - 1][k - 5] + dp[n - 1][k - 6]) and my code: #includeiostream using namespace std; int solve(int n, int k) { int** dp; dp = (int **)malloc(2*sizeof(int*)); dp[0]=(int*)malloc(111*sizeof(int)); dp[1]=(int*)malloc(111*sizeof(int)); for(int i=1;i=6;i++) dp[0][i]=1; int throws=n; n--; int sum=0; while(n--) { for(int i=1;i=k;i++) { dp[1][i]=0; sum=0; for(int j=1;j=6;j++) { if((i-j)0) break; sum+=dp[0][i-j]; } dp[1][i]=sum; } for(int i=1;i=k;i++) dp[0][i]=dp[1][i]; } dp[0][k]*=100; for(int i=0;ithrows;i++) dp[0][k]/=6; return dp[0][k]; } int main() { int cases; cincases; while(cases--) { long n,k; cinnk; coutsolve(n,k)endl; } 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.
Re: [algogeeks] spoj problem double helix
check this test case i/p 2 1 5 1 9 0 o/p 9 your code gives 12... -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://youtube.com/amolsharma99 On Tue, Aug 30, 2011 at 10:27 PM, saurabh singh saurab...@gmail.com wrote: I am repeatedly getting Wrong answer for this problem.I am not sure where I am going wrong. I am finding the intersection point by the normal algorithm(Maintaining two pointers and moving forward the smaller one and I am then concating the elements into their sum about the intersection point) Working for all cases given in comments,forums.and anything else I can think of,,, #includestdio.h int main() { int a[10001],b[10001]; int i,j; int n,m; while(scanf(%d,n)n) { for(i=0;in;i++)scanf(%d,a[i]); scanf(%d,m); for(j=0;jm;j++) scanf(%d,b[j]); int c[10001]={0},d[10001]={0}; i=j=0; int k=0,l=0; long long sum=0; for(i=0,j=0;injm;) { int flag=0; if(a[i]==b[j]) { c[k]+=a[i]; d[l]+=b[j]; //sum=0; k++; l++; flag=1; i++;j++; } if(a[i]b[j]!flag) { c[k]+=a[i]; i++; } else if(a[i]b[j]!flag){ d[l]+=b[j]; j++; } //if(a[i]==b[j]) i++;j++; } if((!i)||(!j)) i=j=0; for(;jm;j++) d[l]+=b[j]; for(;in;i++) c[k]+=a[i]; k++; l++; for(i=0,j=0;ikjl;i++,j++) { if(c[i]d[j]) sum+=c[i]; else sum+=d[j]; } #ifdef DEB for(i=0;ik;i++) printf(%d\t,c[i]); puts(); for(j=0;jl;j++) printf(%d\t,d[j]); puts(); #endif printf(%lld\n,sum); } return 0; } -- 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] SPOJ Problem DIVSUM
hi see the logic all the factors of a number are evenly distributed about it's square root for e.g 100 1 X 100 2 X 50 4 X 25 5 X 20 10 X 10 AFTER THIS THE PAIRS REPEATE THEMSELVES BUT IN OPPOSITE ORDER 20 X 5 25 X 4 50 X 2 100 X 1 SO IF YOU MAKE YOUR LOOP GO TO SQRT(N) AND IF YOU FIND A FACTOR OF THAT NUMBER ANOTHER FACTOR CAN BE FOUND BY DIVING THAT FACTOR WITH THE NUMBER FOR E.G. IF YOU FIND 4 THEN 25 IS FOUND BY 100/4 #includestdio.h #includemath.h main() { long long int n,i,t,d,k,l; // long int a,b; scanf(%lld,t); while(t) { d=0; scanf(%lld,n); k=sqrt(n); for(i=1;i=k;i++) { if((n%i)==0) { d=d+i; l=n/i; if(i!=l) d=d+l; } } printf(%lld\n,d-n); t--; } return (0); } -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @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.
Re: [algogeeks] SPOJ Problem DIVSUM
it can be simply done in O(sqrt(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.
[algogeeks] SPOJ Problem DIVSUM
I am trying to submit solution for the SPOJ DIVSUMhttps://www.spoj.pl/problems/DIVSUM/problem, but it returns the *time limit exceeded*. Code submitted by me is below: #include cstdlib #include iostream using namespace std; int proper_divisor(int number); int main() { int test,i,number; cintest; for(i=0; itest; i++) { cinnumber; proper_divisor(number); } } int proper_divisor(int number) { int i,n=0; for(i=1; inumber-1; i++) { if(number%i==0) { n=n+i; } } //coutn\n; } -- 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/-/vld8Fghb1twJ. 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 DIVSUM
@gaurav Thanks dear Could you please explain the algorithm. -- 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/-/TNa8UygkzGkJ. 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 DIVSUM
Yeah, sorry I was giving a hint for DIVSUM2, which is a much harder version of DIVSUM. You are checking all numbers less than n for divisibility. This is O(n). Figure out how can you find the set of divisors using primes. This can be done in O(2^d), if there are d prime divisors. On Sat, Aug 27, 2011 at 11:10 PM, saurabh modi saurabhmodi102...@gmail.com wrote: you could use seiving.its fast.its practical. -- 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. -- Gaurav Menghani -- 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 ACODE
i am getting repeatdly WA in this question link is https://www.spoj.pl/problems/ACODE/ plzz provide me some test cases where my code fails. my code is # includecstdio # includecstring int main() { while(1) { char a[50100]; scanf(%s,a); int l1=strlen(a); if(a[0]=='0') break; long long int i,j,k=0; for(i=l1-1;i=0;i--) a[i+1]=a[i]; long long int dp[50100]={0}; dp[0]=1; dp[1]=1; for(i=2;i=l1;i++) { long long int s=(a[i-1]-'0')*10+(a[i]-'0'); if(a[i]!='0's=0s=26a[i-1]!='0') dp[i]=dp[i-1]+dp[i-2]; else dp[i]=dp[i-1]; } for(j=0;j=i;j++) { a[j]='\0';} printf(%lld\n,dp[i-1]); } return 0; } -- *WITH REGARDS,* * * *KARTIK SACHAN* *B.TECH 3rd YEAR* *COMPUTER SCIENCE AND ENGINEERING* *NIT 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.
[algogeeks] SPOJ Problem
Hi everybody, I am trying to solve the below mentioned SPOJ problem. I am not getting that how it returns *11 56 *in 3rd test. SPOJ Problem: http://www.spoj.pl/problems/CMPLS/ Sincerely, Rahul Verma -- 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
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.
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.
[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] SPOJ 9199. Circular Track
any1?? On Sun, Aug 7, 2011 at 7:16 PM, Prakash D cegprak...@gmail.com wrote: yeah, i also need to know the approach for this kind of problems asked in many places On Sun, Aug 7, 2011 at 3:58 PM, arvind kumar arvindk...@gmail.com wrote: Hi Can any1 pls help me in solving this? Two persons are running on a circular track either in the same direction or in the opposite direction, indefinitely. The speed of both of them is given to you. Speed will be positive in clockwise direction, and negative in anticlockwise direction. Print the number of distinct points, at which they will meet on the circle. -- 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: Re: [algogeeks] SPOJ 9199. Circular Track
divide absolute speeds by their GCD..and then the answer is their relative speed.. VM NSIT, Dwarka 3rd year, COE On , Prakash D cegprak...@gmail.com wrote: any1?? On Sun, Aug 7, 2011 at 7:16 PM, Prakash D cegprak...@gmail.com wrote: yeah, i also need to know the approach for this kind of problems asked in many places On Sun, Aug 7, 2011 at 3:58 PM, arvind kumar arvindk...@gmail.com wrote: Hi Can any1 pls help me in solving this? Two persons are running on a circular track either in the same direction or in the opposite direction, indefinitely. The speed of both of them is given to you. Speed will be positive in clockwise direction, and negative in anticlockwise direction. Print the number of distinct points, at which they will meet on the circle. -- 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.
[algogeeks] SPOJ CENCRY
this is my codeplz give me any test case where my code fails.i am reaptedly getting WA link is https://www.spoj.pl/problems/CENCRY/ # includecstdio # includecstring char a[]=aeiouaeiouaeiouaeioua; char b[]=bcdfghjklmnpqrstvwxyz; int search(char a1) { int i; if(a1=='a'||a1=='e'||a1=='i'||a1=='o'||a1=='u') { for(i=0;i5;i++) if(a1==a[i]) {return i;break;} } else { for(i=0;i22;i++) if(a1==b[i]) {return i;break;} } } int main() { int l1=strlen(a); int l2=strlen(b); char c[6]; int t; scanf(%d,t); int j; for(j=0;jt;j++) { int d[1000]; int pos=0; scanf(%s,c); int i; for(i=0;i200;i++) d[i]=-1; for(i=0;c[i]!='\0';i++) { d[c[i]]++; pos=search(c[i]); if(c[i]=='a'||c[i]=='e'||c[i]=='i'||c[i]=='o'||c[i]=='u') { printf(%c,b[(pos+d[c[i]]*5)%21]); //printf( %d\n,(pos+d[c[i]]*5)%21); } else if (d[c[i]]==0) printf(%c,a[pos]); else printf(%c,a[pos+(d[c[i]]*21+d[c[i]])%21]); } printf(\n); } return 0; } plzz help me.. -- *WITH REGARDS,* * * *KARTIK SACHAN* *B.TECH 3rd YEAR* *COMPUTER SCIENCE AND ENGINEERING* *NIT 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.
[algogeeks] SPOJ 9199. Circular Track
Hi Can any1 pls help me in solving this? Two persons are running on a circular track either in the same direction or in the opposite direction, indefinitely. The speed of both of them is given to you. Speed will be positive in clockwise direction, and negative in anticlockwise direction. Print the number of distinct points, at which they will meet on the circle. -- 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 9199. Circular Track
yeah, i also need to know the approach for this kind of problems asked in many places On Sun, Aug 7, 2011 at 3:58 PM, arvind kumar arvindk...@gmail.com wrote: Hi Can any1 pls help me in solving this? Two persons are running on a circular track either in the same direction or in the opposite direction, indefinitely. The speed of both of them is given to you. Speed will be positive in clockwise direction, and negative in anticlockwise direction. Print the number of distinct points, at which they will meet on the circle. -- 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 ABCD
i attempted a problem http://www.spoj.pl/problems/ABCD/ my logic is scan the input string and record the count of A, B, C, D in array of size 4 now sort the count array in the output array at first position put an element from count array whose count is less than n and not equal to element above them... then for other positions put element from the count array whose count is less(minimum) than n and they are not equal to previous element and element above them... it is working fine for most of the cases but i was able to figure out the cases where it failed input - BCDBCD output - ABACAH which is wrong it should be ABADAC or ADACAB. i am getting a run time error on submission Please help me in correcting my logic to reach to the correct solution. My Code is as follows - #includeiostream #includecstdio #includevector #includealgorithm #includemap using namespace std; //problem four colours ABCD bool myfunc(pairchar,int i,pairchar,int j) { return (i.second j.second); } int main() { int n; scanf(%d,n); //now up and down array should have 2n colours and each colour should be present n times vector pairchar,int count(4); //count array will store the frequency of each colour int i,j; char k,down[10]; string up; count[0].first='A'; count[1].first='B'; count[2].first='C'; count[3].first='D'; count[0].second=count[1].second=count[2].second=count[3].second=0; cin up; //string up is scanned //get the count of each colour in up string for(i=0;i2*n;i++) { count[up[i]-'A'].second+=1; } /* for(j=0;j4;j++) printf(%c\t%d\t,count[j].first,count[j].second); printf(\n);*/ //now scan the above string and construct the down string together for(i=0;i2*n;i++) { sort(count.begin(),count.end(),myfunc); /*for(j=0;j4;j++) printf(%c\t%d\t,count[j].first,count[j].second); printf(\n);*/ if(i==0) { //this is the case when we have first element to fill k='A'; while(count[k-'A'].second=n||count[k-'A'].first==up[i]) k++; down[i]=count[k-'A'].first; count[k-'A'].second+=1; } else { k='A'; while(count[k-'A'].second=n||count[k-'A'].first==up[i]||count[k-'A'].first==down[i-1]) k++; down[i]=count[k-'A'].first; count[k-'A'].second+=1; } /*printf(Hi\n); for(j=0;j4;j++) printf(%c\t%d\t,count[j].first,count[j].second); printf(\n);*/ } down[2*n]='\0'; coutdown; //system(pause); return 0; } -- Amol Sharma Third Year Student Computer Science and Engineering 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.
[algogeeks] SPOJ LITE
hi everyone...i came across a quite simple problem on spoj... https://www.spoj.pl/problems/LITE/ obvious solution will be O(n)...but it is getting TLE... so we have to improve the complexity to O(logn)..can some suggest the segment tree implementation of this problem i am new to segment treeso please explain how can we make use of segment tree to solve this particular problem in O(logn) !! -- Amol Sharma Third Year Student Computer Science and Engineering 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.
[algogeeks] SPOJ
www.spoj.pl/problems/SHOP Its a pretty easy Q... But m not able to figure out any silly mistake in my prog.. plzz help #includeiostream #includevector #includemap #includequeue using namespace std; char a[26][26]; int si, sj, di, dj, rows, cols; void BFS(vector vectorint v, int si, int sj, int rows, int cols); int safe(vector vectorint v, int r, int c, int current, int rows, int cols); int main() { freopen(input.txt, r, stdin); freopen(output.txt, w, stdout); int si, sj; while(1) { cin cols rows; if(rows == 0 cols == 0) break; vectorint row(26, INT_MAX); vector vectorint final(26, row); for(int i=0; irows; i++) for(int j=0; jcols; j++) { cin a[i][j]; if(a[i][j] == 'S') { si = i; sj = j; } else if(a[i][j] == 'D') { di = i; dj = j; a[i][j] = '0'; } } BFS(final, si, sj, rows, cols); cout final[di][dj] endl; /* for(int i=0; irows; i++) { for(int j=0; jcols; j++) cout final[i][j] ; cout endl; } cout endl; */ } return 0; } void BFS(vector vectorint v, int si, int sj, int rows, int cols) { pairint, int p; queue pairint, int q; q.push(make_pair(si, sj)); v[si][sj] = 0; while(!q.empty()) { p = q.front(); q.pop(); int current = v[p.first][p.second]; if(safe(v, p.first+1, p.second, current, rows, cols)) q.push(make_pair(p.first+1, p.second)); if(safe(v, p.first-1, p.second, current, rows, cols)) q.push(make_pair(p.first-1, p.second)); if(safe(v, p.first, p.second+1, current, rows, cols)) q.push(make_pair(p.first, p.second+1)); if(safe(v, p.first, p.second-1, current, rows, cols)) q.push(make_pair(p.first, p.second-1)); } } int safe(vector vectorint v, int r, int c, int current, int rows, int cols) { if(r = 0 r rows c = 0 c cols a[r][c] != 'X') { if(v[r][c] current + a[r][c] - '0') { v[r][c] = current + a[r][c] - '0'; return 1; } } 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.
Re: [algogeeks] SPOJ
there's something called spoj forum, try posting it there secondly, ask whether ur algo is right or wrong, not the code On Sat, Jul 23, 2011 at 4:51 PM, KK kunalkapadi...@gmail.com wrote: www.spoj.pl/problems/SHOP Its a pretty easy Q... But m not able to figure out any silly mistake in my prog.. plzz help #includeiostream #includevector #includemap #includequeue using namespace std; char a[26][26]; int si, sj, di, dj, rows, cols; void BFS(vector vectorint v, int si, int sj, int rows, int cols); int safe(vector vectorint v, int r, int c, int current, int rows, int cols); int main() { freopen(input.txt, r, stdin); freopen(output.txt, w, stdout); int si, sj; while(1) { cin cols rows; if(rows == 0 cols == 0) break; vectorint row(26, INT_MAX); vector vectorint final(26, row); for(int i=0; irows; i++) for(int j=0; jcols; j++) { cin a[i][j]; if(a[i][j] == 'S') { si = i; sj = j; } else if(a[i][j] == 'D') { di = i; dj = j; a[i][j] = '0'; } } BFS(final, si, sj, rows, cols); cout final[di][dj] endl; /* for(int i=0; irows; i++) { for(int j=0; jcols; j++) cout final[i][j] ; cout endl; } cout endl; */ } return 0; } void BFS(vector vectorint v, int si, int sj, int rows, int cols) { pairint, int p; queue pairint, int q; q.push(make_pair(si, sj)); v[si][sj] = 0; while(!q.empty()) { p = q.front(); q.pop(); int current = v[p.first][p.second]; if(safe(v, p.first+1, p.second, current, rows, cols)) q.push(make_pair(p.first+1, p.second)); if(safe(v, p.first-1, p.second, current, rows, cols)) q.push(make_pair(p.first-1, p.second)); if(safe(v, p.first, p.second+1, current, rows, cols)) q.push(make_pair(p.first, p.second+1)); if(safe(v, p.first, p.second-1, current, rows, cols)) q.push(make_pair(p.first, p.second-1)); } } int safe(vector vectorint v, int r, int c, int current, int rows, int cols) { if(r = 0 r rows c = 0 c cols a[r][c] != 'X') { if(v[r][c] current + a[r][c] - '0') { v[r][c] = current + a[r][c] - '0'; return 1; } } 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
I agree with Shady on asking for algo for the problem but lets not be hard on posting spoj question on spoj forum as these too involves algorithm (our interest). @KK : Can you tell us the judging status you are hitting? (Wrong answer, timeout??). ~Viswanath. On Sat, Jul 23, 2011 at 4:57 PM, shady sinv...@gmail.com wrote: there's something called spoj forum, try posting it there secondly, ask whether ur algo is right or wrong, not the code On Sat, Jul 23, 2011 at 4:51 PM, KK kunalkapadi...@gmail.com wrote: www.spoj.pl/problems/SHOP Its a pretty easy Q... But m not able to figure out any silly mistake in my prog.. plzz help #includeiostream #includevector #includemap #includequeue using namespace std; char a[26][26]; int si, sj, di, dj, rows, cols; void BFS(vector vectorint v, int si, int sj, int rows, int cols); int safe(vector vectorint v, int r, int c, int current, int rows, int cols); int main() { freopen(input.txt, r, stdin); freopen(output.txt, w, stdout); int si, sj; while(1) { cin cols rows; if(rows == 0 cols == 0) break; vectorint row(26, INT_MAX); vector vectorint final(26, row); for(int i=0; irows; i++) for(int j=0; jcols; j++) { cin a[i][j]; if(a[i][j] == 'S') { si = i; sj = j; } else if(a[i][j] == 'D') { di = i; dj = j; a[i][j] = '0'; } } BFS(final, si, sj, rows, cols); cout final[di][dj] endl; /* for(int i=0; irows; i++) { for(int j=0; jcols; j++) cout final[i][j] ; cout endl; } cout endl; */ } return 0; } void BFS(vector vectorint v, int si, int sj, int rows, int cols) { pairint, int p; queue pairint, int q; q.push(make_pair(si, sj)); v[si][sj] = 0; while(!q.empty()) { p = q.front(); q.pop(); int current = v[p.first][p.second]; if(safe(v, p.first+1, p.second, current, rows, cols)) q.push(make_pair(p.first+1, p.second)); if(safe(v, p.first-1, p.second, current, rows, cols)) q.push(make_pair(p.first-1, p.second)); if(safe(v, p.first, p.second+1, current, rows, cols)) q.push(make_pair(p.first, p.second+1)); if(safe(v, p.first, p.second-1, current, rows, cols)) q.push(make_pair(p.first, p.second-1)); } } int safe(vector vectorint v, int r, int c, int current, int rows, int cols) { if(r = 0 r rows c = 0 c cols a[r][c] != 'X') { if(v[r][c] current + a[r][c] - '0') { v[r][c] = current + a[r][c] - '0'; return 1; } } 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.
Re: [algogeeks] SPOJ
What will happen if r=di,c=dj in your safe function,I think that is causing the error... On Sat, Jul 23, 2011 at 8:29 PM, viswanath vellaiappan viswanath.vellaiap...@gmail.com wrote: I agree with Shady on asking for algo for the problem but lets not be hard on posting spoj question on spoj forum as these too involves algorithm (our interest). @KK : Can you tell us the judging status you are hitting? (Wrong answer, timeout??). ~Viswanath. On Sat, Jul 23, 2011 at 4:57 PM, shady sinv...@gmail.com wrote: there's something called spoj forum, try posting it there secondly, ask whether ur algo is right or wrong, not the code On Sat, Jul 23, 2011 at 4:51 PM, KK kunalkapadi...@gmail.com wrote: www.spoj.pl/problems/SHOP Its a pretty easy Q... But m not able to figure out any silly mistake in my prog.. plzz help #includeiostream #includevector #includemap #includequeue using namespace std; char a[26][26]; int si, sj, di, dj, rows, cols; void BFS(vector vectorint v, int si, int sj, int rows, int cols); int safe(vector vectorint v, int r, int c, int current, int rows, int cols); int main() { freopen(input.txt, r, stdin); freopen(output.txt, w, stdout); int si, sj; while(1) { cin cols rows; if(rows == 0 cols == 0) break; vectorint row(26, INT_MAX); vector vectorint final(26, row); for(int i=0; irows; i++) for(int j=0; jcols; j++) { cin a[i][j]; if(a[i][j] == 'S') { si = i; sj = j; } else if(a[i][j] == 'D') { di = i; dj = j; a[i][j] = '0'; } } BFS(final, si, sj, rows, cols); cout final[di][dj] endl; /* for(int i=0; irows; i++) { for(int j=0; jcols; j++) cout final[i][j] ; cout endl; } cout endl; */ } return 0; } void BFS(vector vectorint v, int si, int sj, int rows, int cols) { pairint, int p; queue pairint, int q; q.push(make_pair(si, sj)); v[si][sj] = 0; while(!q.empty()) { p = q.front(); q.pop(); int current = v[p.first][p.second]; if(safe(v, p.first+1, p.second, current, rows, cols)) q.push(make_pair(p.first+1, p.second)); if(safe(v, p.first-1, p.second, current, rows, cols)) q.push(make_pair(p.first-1, p.second)); if(safe(v, p.first, p.second+1, current, rows, cols)) q.push(make_pair(p.first, p.second+1)); if(safe(v, p.first, p.second-1, current, rows, cols)) q.push(make_pair(p.first, p.second-1)); } } int safe(vector vectorint v, int r, int c, int current, int rows, int cols) { if(r = 0 r rows c = 0 c cols a[r][c] != 'X') { if(v[r][c] current + a[r][c] - '0') { v[r][c] = current + a[r][c] - '0'; return 1; } } 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. -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- 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 Problem Evaluating Expression
Does anyone know how to simplify the expression for this problem ? https://www.spoj.pl/problems/EXFOR/ To get AC for this problem we can always solve the expression, which is bruteforce, any other better way ? Mathematician's 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.
Re: [algogeeks] SPOJ Problem Evaluating Expression
It forms a pattern for each combination i solved it tht way in spoj. On 7/24/11, shady sinv...@gmail.com wrote: Does anyone know how to simplify the expression for this problem ? https://www.spoj.pl/problems/EXFOR/ To get AC for this problem we can always solve the expression, which is bruteforce, any other better way ? Mathematician's 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. -- Somnath Singh -- 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 problem TAILS
I'm trying to solve this problem: www.spoj.pl/problems/TAILS I tried of eliminating 1's from left to right and from right to left and printed the minimum among them. I got WA. Any other ideas to proceed this 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.
[algogeeks] SPOJ Problem DP
Hi, I am solving this http://www.spoj.pl/problems/DP/ problem using Djikstra's algorithm. What is the dynamic programming solution to this ? PS : Don't post the code, but the states of dp. Thanks. Shady -- 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 GPA1
http://www.spoj.pl/problems/GPA1/ hey guys here is my code and its given WA ...plzz tell me where i am worng..i am tried getting WA in this question # includestdio.h # includestdlib.h int main() { int n; scanf(%d,n); while(n--) { double a,b,c,d,e,f; double cpi[20]={0}; double flag[20]={0}; double a1,a2,a3,a4,a5; char b1[100],b2[100],b3[100],b4[100],b5[100]; int i,j,k,l; int t; int ch =0; scanf(%lf%lf%lf%lf%lf%lf,a,b,c,d,e,f); for(i=0;i6;i++) { scanf(%s%s%s%s%s,b1,b2,b3,b4,b5); a1=atof(b1); a2=atof(b2); a3=atof(b3); a4=atof(b4); a5=atof(b5); //(a1=%lf a2=%lf a3=%lf a4=%lf a5=%lf \n,a1,a2,a3,a4,a5); float max1,max2; if(a1a3a2a3) {max1=a1;max2=a2;} else if(a1a2a3a2) {max1=a1;max2=a3;} else {max1=a2;max2=a3;} //printf(max1=%lf max2=%lf\n,max1,max2); double sum1=((max1+max2)*45)/40; //printf(SUM1=%lf\n,sum1); double sum2=a4/2; double sum3; if(a551) sum3=5; else if(a561) sum3=4; else if(a571) sum3=3; else if(a581) sum3=2; else if(a591) sum3=1; else sum3=0; double total=sum1+sum2+sum3; //printf(TOTAL SUM=%lf\n,total); if(total=91) {cpi[i]=10;flag[i]=1;} else if(total=81) {cpi[i]=9;flag[i]=1;} else if(total=71) {cpi[i]=8;flag[i]=1;} else if(total=61) {cpi[i]=7;flag[i]=1;} else if(total50) {cpi[i]=6;flag[i]=1;} else if(total==50) {cpi[i]=5;flag[i]=1;} else {cpi[i]=0;flag[i]=0;} //printf(sum1=%lf sum2=%lf sum3=%lf total=%lf cpi=%d flag=%d\n,sum1,sum2,sum3,total,cpi[i],flag[i]); } float gpa=(a*cpi[0]+b*cpi[1]+c*cpi[2]+d*cpi[3]+e*cpi[4]+f*cpi[5])/(a+b+c+d+e+f); //printf(sum= %d\n,a+b+c+d+e+f); //printf(gpa =%lf\n,gpa); for(i=0;i6;i++) if(flag[i]==0) { ch=1; break; } if(ch==1) printf(FAILED, %0.2lf\n,gpa); else printf(PASSED, %0.2lf\n,gpa); } return 0; } plzz help me and correct me where i am wrong -- *WITH REGARDS,* * * *KARTIK SACHAN* *B.TECH 2ND YEAR* *COMPUTER SCIENCE AND ENGINEERING* *NIT 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.
[algogeeks] SPOJ STRDIST
http://www.spoj.pl/problems/STRDIST/ Getting WA repeatedly. Can someone help me with the below code. #include iostream #include string #include stdio.h #include algorithm using namespace std; int main() { int k,l; scanf(%d %d,k,l); string str1 = ; string str2 = ; if (k0) cin str1; if(l0) cin str2; str1 = 0 + str1; str2 = 0 + str2; int m,n; m = k; n = l; int pos[][3] = { {2,1,0}, {0,2,1}, {1,0,2} }; int I,I1,I2; int posIdx = 0; int dp[3][n+1]; for (int i = 0 ; i 3; i++) for (int j = 0 ; j =n; j++) dp[i][j] = 200; dp[0][0] = 0; for (int i = 0 ; i = m; i++) { if (i = 2) { I = pos[posIdx][0]; I1 = pos[posIdx][1]; I2 = pos[posIdx][2]; } else { I=i;I1=i-1; } for (int j = 0 ; j =n; j++) { if (i == 0 j == 0) continue; if ( j - i 105) break; bool updated = false; if (j 0) { dp[I][j] = min(dp[I][j],dp[I][j-1] + 1); updated = true; } if (i 0) { if (updated) dp[I][j] = min(dp[I][j],dp[I1][j] + 1); else dp[I][j] = dp[I1][j] + 1; } if (i 0 j 0 str1[i] == str2[j]) { dp[I][j] = min(dp[I][j],dp[I1][j-1]); } if (str1[i] == str2[j-1] str1[i-1] == str2[j] i=2 j=2) { dp[I][j] = min(dp[I][j],dp[I2][j-2] + 1); } if (i 0 j 0 str1[i] != str2[j]) { dp[I][j] = min(dp[I][j],dp[I1][j-1] + 1); } } if (i = 2) { posIdx = (posIdx + 1)%3; } } printf(%d\n,dp[k%3][l]); 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.
Re: [algogeeks] spoj shlights
@ kartik sachan Problem with this code is this- All GB pairs should be process in one time period On 6/23/11, kartik sachan kartik.sac...@gmail.com wrote: QUESTION LINK IS http://www.spoj.pl/problems/SHLIGHTS/ MY CODE IS GIVEN BELOW ITS IS GIVING TLEPLZZ HELP ME OUT # includecstdio # includecstring int main() { int t; char a[17]; scanf(%d,t); int i,j,k; while(t--) { int count=0; int flag=0,flag1=0; scanf(%s,a); while(1) { for(i=0;a[i]!='\0';i++) if(a[i]=='G'a[i+1]=='B') {a[i]='B';a[i+1]='G';i=i+1;flag1=1;} if(flag1==1) {count++;flag1=0;} if(count =flag) break; flag=count; } printf(%d\n,count); } return 0; } PLZZ HELP ME OUT OR SUGGEST ANY OTHER LOGIC IF IT HAS SOME MISTAKES -- *WITH REGARDS,* * * *KARTIK SACHAN* *B.TECH 2ND YEAR* *COMPUTER SCIENCE AND ENGINEERING* *NIT 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.
[algogeeks] spoj shlights
QUESTION LINK IS http://www.spoj.pl/problems/SHLIGHTS/ MY CODE IS GIVEN BELOW ITS IS GIVING TLEPLZZ HELP ME OUT # includecstdio # includecstring int main() { int t; char a[17]; scanf(%d,t); int i,j,k; while(t--) { int count=0; int flag=0,flag1=0; scanf(%s,a); while(1) { for(i=0;a[i]!='\0';i++) if(a[i]=='G'a[i+1]=='B') {a[i]='B';a[i+1]='G';i=i+1;flag1=1;} if(flag1==1) {count++;flag1=0;} if(count =flag) break; flag=count; } printf(%d\n,count); } return 0; } PLZZ HELP ME OUT OR SUGGEST ANY OTHER LOGIC IF IT HAS SOME MISTAKES -- *WITH REGARDS,* * * *KARTIK SACHAN* *B.TECH 2ND YEAR* *COMPUTER SCIENCE AND ENGINEERING* *NIT 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.
[algogeeks] spoj problem chairs
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.