Re: [algogeeks] spoj problem EASYMATH

2012-09-29 Thread Wladimir Tavares
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

2012-09-28 Thread atul anand
@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

2012-09-28 Thread icy`
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

2012-09-27 Thread ashish pant
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

2012-09-27 Thread atul anand
@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

2012-09-27 Thread Wladimir Tavares
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

2012-09-26 Thread gaurav yadav
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

2012-09-25 Thread gaurav yadav
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

2012-06-24 Thread Sourabh Singh
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

2012-06-24 Thread Hassan Monfared
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

2012-06-24 Thread shady
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

2012-06-22 Thread Pradip Singh
@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

2012-06-22 Thread Pradip Singh
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

2012-06-21 Thread Bhavesh agrawal
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

2012-06-21 Thread Mayank Singh
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

2012-06-21 Thread Bhavesh agrawal
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

2012-06-21 Thread Mayank Singh
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

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

 here is my code :

 #includestdio.h
 #includestdlib.h

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

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

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


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



Re: [algogeeks] SPOJ problem : CANDY III

2012-06-21 Thread amrit harry
@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 problem : CANDY

2012-06-20 Thread Mayank Singh
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

2012-06-20 Thread Bhavesh agrawal
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

2012-06-20 Thread Mayank Singh
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

2012-06-20 Thread Bhavesh agrawal
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

2012-06-20 Thread Krishnan
@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

2012-06-20 Thread Mayank Singh
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 problem : POKER

2012-06-18 Thread Mayank Singh
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

2012-06-17 Thread Mayank Singh
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

2012-06-17 Thread Pranjal Patil
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

2012-06-12 Thread gaurav yadav
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

2012-05-13 Thread Krishnan
@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 problem

2012-01-23 Thread Anil Arya
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)

[algogeeks] spoj problem

2011-11-14 Thread Anshul AGARWAL
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

2011-11-14 Thread shady
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

2011-11-14 Thread Anshul AGARWAL
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

2011-11-14 Thread sunny agrawal
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.



[algogeeks] SPOJ problem

2011-09-17 Thread amrit harry
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.



Re: [algogeeks] spoj problem double helix

2011-08-30 Thread Amol Sharma
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

2011-08-29 Thread UTKARSH SRIVASTAV
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

2011-08-28 Thread kartik sachan
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

2011-08-27 Thread Rahul Verma
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

2011-08-27 Thread Rahul Verma
@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

2011-08-27 Thread Gaurav Menghani
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 Problem

2011-08-25 Thread Rahul Verma
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.



[algogeeks] SPOJ Problem Evaluating Expression

2011-07-23 Thread shady
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

2011-07-23 Thread SAMM
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

2011-07-04 Thread cegprakash
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

2011-07-01 Thread shady
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 problem chairs

2011-06-19 Thread saurabh singh
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.



Re: [algogeeks] spoj problem chairs

2011-06-19 Thread abc abc
@above   Better you ask it on spoj forum
On Sun, Jun 19, 2011 at 7:27 PM, saurabh singh saurab...@gmail.com wrote:

 I am getting WA for this problem.I dont know whether its case of overflow
 or I have come up with a wrong formula,
 https://www.spoj.pl/problems/CHAIR/
 I am coding in python so I dont think there is probblem of overflow.

 def f(n):
 if n0:
 return 0
 if n==0:
 return 1
 i=n
 prod=1
 while i0 :
 prod*=i
 i-=1
 return prod
 n=input()
 k=input()
 if k==1:
 print n
 elif 2*kn:
 print 0
 else :
 x=f(n-1)
 y=f(n-k)*f(k)
 print (x-y)%13


 --
 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT ALLAHABAD


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


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



Re: [algogeeks] Spoj Problem Help

2011-06-05 Thread tec
The final sequence should be (0,0),(1,1),(2,3),(3,5),(5,8)...

 (0,0) and (0,1) both finishes in 0 iteration.
 (1,2)-(0,1) and (1,1)-(0,1) both finishes in 1 iteration.
So (0,1) and (1,2) is discarded.

For the rest: (0,1) - (1,2) - (2,3) - (3,5) - (5,8) - ...
finishes in:   2   3  4
 ... iterations respectively.

2011/5/23 Akshata Sharma akshatasharm...@gmail.com:
 @tec: the sequence should be like (0,1),(1,1),(1,2),(2,3),(3,5),(5,8)... or
 m i wrong?

 On Mon, May 23, 2011 at 11:08 AM, Aakash Johari aakashj@gmail.com
 wrote:

 Matrix exponentiation can help i think

 On Sun, May 22, 2011 at 10:36 PM, Akshata Sharma
 akshatasharm...@gmail.com wrote:

 It appers that the problem is just to find the (N+3)th fibonacci number
 for given N. Since N is very large, how to find nth fibonaci number for such
 a large n??

 On Mon, May 23, 2011 at 7:51 AM, tec technic@gmail.com wrote:

 Try thinking backwards.
 (0,1),(1,2),(2,3),(3,5),(5,8),(8,13),...

 2011/5/22 shady sinv...@gmail.com:
  Hey,
  Can anyone tell how to solve this problem in Spoj ? I went through
  some material but there all they were discussing was on complexity and
  not on actual number of iterations.
  http://www.spoj.pl/problems/MAIN74/
 
  Thanks.
 
  --
  You received this message because you are subscribed to the Google
  Groups Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from 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.



 --
 -Aakash Johari
 (IIIT Allahabad)




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

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




-- 
__

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



[algogeeks] spoj problem acode

2011-06-01 Thread pacific :-)
Link : https://www.spoj.pl/problems/ACODE/

25114
BEAN’, ‘BEAAD’, ‘YAAD’, ‘YAN’, ‘YKD’ ‘BEKD’.
How many different decodings?”

My soln , but i get TLE.Please help.

#include iostream
#include cstdio
#include vector
using namespace std;

char * head;
int result[5001];
int count(char * a ,int size)
{
  if(result[a-head]!=0){
return result[a-head];
  }

  if(size==1)
return 1;
  else if (size==2)
{
  if(a[0]'2')
return 1;
  else
return 2;
}
  else
{
  int temp = count(a+1,size-1);
  if(a[0]'2' || (a[0]=='2'  a[1]'6'))
  {
result[a-head] = temp ;
return temp;
  }
  else
  {
int r = temp+count(a+2,size-2);
result[a-head] = r;
return r;
  }
}
}

int main()
{
  char ch;
  cinch;
  while(ch!='0')
{
  char input[5001];
  int index=0;
  while(ch!='\n')
{
  //input.push_back(ch-'0');
  input[index]=ch;
  index++;
  scanf(%c,ch);
}

  cinch;
  head = input ;
  for(int i=0;i=5000;i++)
result[i]=0;
  coutcount(input,index)endl;
}
return 0;
}

-- 
regards,
chinna.

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



Re: [algogeeks] spoj problem acode

2011-06-01 Thread arun kumar
hey me getting wrong ans..can anyone pls help me out
here s my code
#includestdio.h
#includeiostream
#includestring
#includecstring
using namespace std;
unsigned long long a[5001]={0};
unsigned long long fun(string s,int n)
{
if(n==0) return 1;
if(a[n]) return a[n];

int c=0,d=0;
c=s[n]-'0';
d=s[n-1]-'0';
unsigned long long ans=a[n];
   // coutcdendl;
if((d*10+c)=26  n!=1)
ans+=fun(s,n-2);
else if((d*10+c)=26)
ans+=fun(s,0);
if(d!=0)
ans+=fun(s,n-1);
return ans;


}
main()
{
string s;
while(cins  s[0]!='0')
{
memset(a,0,sizeof(a));
coutfun(s,s.size()-1);

}
}


On Wed, Jun 1, 2011 at 3:30 PM, pacific :-) pacific4...@gmail.com wrote:
 Link : https://www.spoj.pl/problems/ACODE/

 25114
 BEAN’, ‘BEAAD’, ‘YAAD’, ‘YAN’, ‘YKD’ ‘BEKD’.
 How many different decodings?”

 My soln , but i get TLE.Please help.

 #include iostream
 #include cstdio
 #include vector
 using namespace std;

 char * head;
 int result[5001];
 int count(char * a ,int size)
 {
   if(result[a-head]!=0){
     return result[a-head];
   }

   if(size==1)
     return 1;
   else if (size==2)
     {
   if(a[0]'2')
     return 1;
   else
     return 2;
     }
   else
     {
   int temp = count(a+1,size-1);
   if(a[0]'2' || (a[0]=='2'  a[1]'6'))
   {
     result[a-head] = temp ;
     return temp;
   }
   else
   {
     int r = temp+count(a+2,size-2);
     result[a-head] = r;
     return r;
   }
     }
 }

 int main()
 {
   char ch;
   cinch;
   while(ch!='0')
     {
   char input[5001];
   int index=0;
   while(ch!='\n')
     {
   //input.push_back(ch-'0');
   input[index]=ch;
   index++;
   scanf(%c,ch);
     }

   cinch;
   head = input ;
   for(int i=0;i=5000;i++)
     result[i]=0;
   coutcount(input,index)endl;
     }
 return 0;
 }

 --
 regards,
 chinna.

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


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



Re: [algogeeks] spoj problem acode

2011-06-01 Thread keyan karthi
 even if the left over string length is 1 so that the recursion can be
fun(s,current_position-2),  u still have the option for choosing a single
character... do u get it??
thats where u go wrong... :) the rec call should be return
fun(cur_length-1)+fun(cur_len-2) ...

On Wed, Jun 1, 2011 at 3:34 PM, arun kumar kumar0...@gmail.com wrote:

 hey me getting wrong ans..can anyone pls help me out
 here s my code
 #includestdio.h
 #includeiostream
 #includestring
 #includecstring
 using namespace std;
 unsigned long long a[5001]={0};
 unsigned long long fun(string s,int n)
 {
if(n==0) return 1;
if(a[n]) return a[n];

int c=0,d=0;
c=s[n]-'0';
d=s[n-1]-'0';
unsigned long long ans=a[n];
   // coutcdendl;
if((d*10+c)=26  n!=1)
ans+=fun(s,n-2);
else if((d*10+c)=26)
ans+=fun(s,0);
if(d!=0)
ans+=fun(s,n-1);
return ans;


 }
 main()
 {
string s;
while(cins  s[0]!='0')
{
memset(a,0,sizeof(a));
coutfun(s,s.size()-1);

}
 }


 On Wed, Jun 1, 2011 at 3:30 PM, pacific :-) pacific4...@gmail.com wrote:
  Link : https://www.spoj.pl/problems/ACODE/
 
  25114
  BEAN’, ‘BEAAD’, ‘YAAD’, ‘YAN’, ‘YKD’ ‘BEKD’.
  How many different decodings?”
 
  My soln , but i get TLE.Please help.
 
  #include iostream
  #include cstdio
  #include vector
  using namespace std;
 
  char * head;
  int result[5001];
  int count(char * a ,int size)
  {
if(result[a-head]!=0){
  return result[a-head];
}
 
if(size==1)
  return 1;
else if (size==2)
  {
if(a[0]'2')
  return 1;
else
  return 2;
  }
else
  {
int temp = count(a+1,size-1);
if(a[0]'2' || (a[0]=='2'  a[1]'6'))
{
  result[a-head] = temp ;
  return temp;
}
else
{
  int r = temp+count(a+2,size-2);
  result[a-head] = r;
  return r;
}
  }
  }
 
  int main()
  {
char ch;
cinch;
while(ch!='0')
  {
char input[5001];
int index=0;
while(ch!='\n')
  {
//input.push_back(ch-'0');
input[index]=ch;
index++;
scanf(%c,ch);
  }
 
cinch;
head = input ;
for(int i=0;i=5000;i++)
  result[i]=0;
coutcount(input,index)endl;
  }
  return 0;
  }
 
  --
  regards,
  chinna.
 
  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 

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



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



Re: [algogeeks] spoj problem acode

2011-06-01 Thread keyan karthi
oops.. :P that an if didnt notice tat :D

On Wed, Jun 1, 2011 at 8:34 PM, keyan karthi keyankarthi1...@gmail.comwrote:

  even if the left over string length is 1 so that the recursion can be
 fun(s,current_position-2),  u still have the option for choosing a single
 character... do u get it??
 thats where u go wrong... :) the rec call should be return
 fun(cur_length-1)+fun(cur_len-2) ...


 On Wed, Jun 1, 2011 at 3:34 PM, arun kumar kumar0...@gmail.com wrote:

 hey me getting wrong ans..can anyone pls help me out
 here s my code
 #includestdio.h
 #includeiostream
 #includestring
 #includecstring
 using namespace std;
 unsigned long long a[5001]={0};
 unsigned long long fun(string s,int n)
 {
if(n==0) return 1;
if(a[n]) return a[n];

int c=0,d=0;
c=s[n]-'0';
d=s[n-1]-'0';
unsigned long long ans=a[n];
   // coutcdendl;
if((d*10+c)=26  n!=1)
ans+=fun(s,n-2);
else if((d*10+c)=26)
ans+=fun(s,0);
if(d!=0)
ans+=fun(s,n-1);
return ans;


 }
 main()
 {
string s;
while(cins  s[0]!='0')
{
memset(a,0,sizeof(a));
coutfun(s,s.size()-1);

}
 }


 On Wed, Jun 1, 2011 at 3:30 PM, pacific :-) pacific4...@gmail.com
 wrote:
  Link : https://www.spoj.pl/problems/ACODE/
 
  25114
  BEAN’, ‘BEAAD’, ‘YAAD’, ‘YAN’, ‘YKD’ ‘BEKD’.
  How many different decodings?”
 
  My soln , but i get TLE.Please help.
 
  #include iostream
  #include cstdio
  #include vector
  using namespace std;
 
  char * head;
  int result[5001];
  int count(char * a ,int size)
  {
if(result[a-head]!=0){
  return result[a-head];
}
 
if(size==1)
  return 1;
else if (size==2)
  {
if(a[0]'2')
  return 1;
else
  return 2;
  }
else
  {
int temp = count(a+1,size-1);
if(a[0]'2' || (a[0]=='2'  a[1]'6'))
{
  result[a-head] = temp ;
  return temp;
}
else
{
  int r = temp+count(a+2,size-2);
  result[a-head] = r;
  return r;
}
  }
  }
 
  int main()
  {
char ch;
cinch;
while(ch!='0')
  {
char input[5001];
int index=0;
while(ch!='\n')
  {
//input.push_back(ch-'0');
input[index]=ch;
index++;
scanf(%c,ch);
  }
 
cinch;
head = input ;
for(int i=0;i=5000;i++)
  result[i]=0;
coutcount(input,index)endl;
  }
  return 0;
  }
 
  --
  regards,
  chinna.
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 

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




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



Re: [algogeeks] SPOJ Problem Help

2011-05-30 Thread oldman
Code::Blocks

On Sun, May 29, 2011 at 1:59 AM, Akash Mukherjee akash...@gmail.com wrote:

 devcpp


 On Sat, May 28, 2011 at 11:17 PM, sravanreddy001 sravanreddy...@gmail.com
  wrote:

 Hi all. Can some one provide a good C editor.. preferable GUI one, that
 works on windows 7.

 I'm good with Java, but. now would like to get some hands on C, C++
 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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 Problem Help

2011-05-28 Thread Akshata Sharma
My code gives TLE. What further optimization is required in my code??
https://www.spoj.pl/problems/FACVSPOW/

/*FACVSPOW*/
#includestdio.h
#includecmath

using namespace std;

int calc(long n, long a)
{
 if(((n*log(n)-n)+0.5*log(2*M_PI*n)-n*log(a))=0)
 return 1;
 else return -1;
}
int main()
{
long t;
scanf(%ld,t);
long a;
while(t--)
{
 scanf(%ld,a);
 long lo=2*a;
 long hi=(long)(2.718281828*a) + 1;
 long mid;
 while(lohi)
 {
  mid=(lo+hi)/2;
  if(calc(mid,a)0)
  lo=mid+1
  else if(calc(mid,a)0)
  hi=mid;

  if(calc(mid,a)0  calc(mid-1,a)0)
  break;
 }
  printf(%ld\n,mid);
}
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 Help

2011-05-28 Thread Aakash Johari
Precompute the values. and then do queries.

On Sat, May 28, 2011 at 1:46 AM, Akshata Sharma
akshatasharm...@gmail.comwrote:

 My code gives TLE. What further optimization is required in my code??
 https://www.spoj.pl/problems/FACVSPOW/


 /*FACVSPOW*/
 #includestdio.h
 #includecmath

 using namespace std;

 int calc(long n, long a)
 {
  if(((n*log(n)-n)+0.5*log(2*M_PI*n)-n*log(a))=0)

  return 1;
  else return -1;
 }
 int main()
 {
 long t;
 scanf(%ld,t);
 long a;
 while(t--)
 {
  scanf(%ld,a);

  long lo=2*a;

  long hi=(long)(2.718281828*a) + 1;

  long mid;
  while(lohi)

  {
   mid=(lo+hi)/2;

   if(calc(mid,a)0)

   lo=mid+1
   else if(calc(mid,a)0)

   hi=mid;

   if(calc(mid,a)0  calc(mid-1,a)0)

   break;
  }
   printf(%ld\n,mid);
 }
 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.




-- 
-Aakash Johari
(IIIT 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 Help

2011-05-28 Thread sukhmeet singh
follow what Akash said..!!
in case you still need help just go through http://ideone.com/al0U0  in
devcpp..!!

On Sat, May 28, 2011 at 2:34 PM, Aakash Johari aakashj@gmail.comwrote:

 Precompute the values. and then do queries.


 On Sat, May 28, 2011 at 1:46 AM, Akshata Sharma akshatasharm...@gmail.com
  wrote:

 My code gives TLE. What further optimization is required in my code??
 https://www.spoj.pl/problems/FACVSPOW/


 /*FACVSPOW*/
 #includestdio.h

 #includecmath


 using namespace std;


 int calc(long n, long a)

 {
  if(((n*log(n)-n)+0.5*log(2*M_PI*n)-n*log(a))=0)


  return 1;
  else return -1;

 }
 int main()

 {
 long t;
 scanf(%ld,t);

 long a;
 while(t--)

 {
  scanf(%ld,a);


  long lo=2*a;


  long hi=(long)(2.718281828*a) + 1;


  long mid;
  while(lohi)


  {
   mid=(lo+hi)/2;


   if(calc(mid,a)0)


   lo=mid+1
   else if(calc(mid,a)0)


   hi=mid;

   if(calc(mid,a)0  calc(mid-1,a)0)


   break;
  }
   printf(%ld\n,mid);

 }
 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.




 --
 -Aakash Johari
 (IIIT 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 Help

2011-05-28 Thread Logic King
@sukhmeetyour code is having runtime error !!

On Sat, May 28, 2011 at 4:48 AM, sukhmeet singh sukhmeet2...@gmail.comwrote:

 follow what Akash said..!!
 in case you still need help just go through http://ideone.com/al0U0  in
 devcpp..!!

 On Sat, May 28, 2011 at 2:34 PM, Aakash Johari aakashj@gmail.comwrote:

 Precompute the values. and then do queries.


 On Sat, May 28, 2011 at 1:46 AM, Akshata Sharma 
 akshatasharm...@gmail.com wrote:

 My code gives TLE. What further optimization is required in my code??
 https://www.spoj.pl/problems/FACVSPOW/




 /*FACVSPOW*/
 #includestdio.h



 #includecmath




 using namespace std;




 int calc(long n, long a)



 {
  if(((n*log(n)-n)+0.5*log(2*M_PI*n)-n*log(a))=0)




  return 1;
  else return -1;



 }
 int main()



 {
 long t;
 scanf(%ld,t);



 long a;
 while(t--)



 {
  scanf(%ld,a);




  long lo=2*a;




  long hi=(long)(2.718281828*a) + 1;




  long mid;
  while(lohi)




  {
   mid=(lo+hi)/2;




   if(calc(mid,a)0)




   lo=mid+1
   else if(calc(mid,a)0)




   hi=mid;

   if(calc(mid,a)0  calc(mid-1,a)0)




   break;
  }
   printf(%ld\n,mid);



 }
 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.




 --
 -Aakash Johari
 (IIIT Allahabad)





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


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


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



Re: [algogeeks] SPOJ Problem Help

2011-05-28 Thread sukhmeet singh
don't see the online compiler.. it doesn't allow such a large array.. try on
LINUX..
this is the one I got a/c  on SPOJ ..!! http://ideone.com/NdBYJ

On Sat, May 28, 2011 at 5:26 PM, Logic King crazy.logic.k...@gmail.comwrote:

 @sukhmeetyour code is having runtime error !!


 On Sat, May 28, 2011 at 4:48 AM, sukhmeet singh sukhmeet2...@gmail.comwrote:

 follow what Akash said..!!
 in case you still need help just go through http://ideone.com/al0U0  in
 devcpp..!!

 On Sat, May 28, 2011 at 2:34 PM, Aakash Johari aakashj@gmail.comwrote:

 Precompute the values. and then do queries.


 On Sat, May 28, 2011 at 1:46 AM, Akshata Sharma 
 akshatasharm...@gmail.com wrote:

 My code gives TLE. What further optimization is required in my code??
 https://www.spoj.pl/problems/FACVSPOW/





 /*FACVSPOW*/
 #includestdio.h




 #includecmath





 using namespace std;





 int calc(long n, long a)




 {
  if(((n*log(n)-n)+0.5*log(2*M_PI*n)-n*log(a))=0)





  return 1;
  else return -1;




 }
 int main()




 {
 long t;
 scanf(%ld,t);




 long a;
 while(t--)




 {
  scanf(%ld,a);





  long lo=2*a;





  long hi=(long)(2.718281828*a) + 1;





  long mid;
  while(lohi)





  {
   mid=(lo+hi)/2;





   if(calc(mid,a)0)





   lo=mid+1
   else if(calc(mid,a)0)





   hi=mid;

   if(calc(mid,a)0  calc(mid-1,a)0)





   break;
  }
   printf(%ld\n,mid);




 }
 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.




 --
 -Aakash Johari
 (IIIT Allahabad)





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


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


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


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



Re: [algogeeks] SPOJ Problem Help

2011-05-28 Thread Akshata Sharma
thanks all :)

On Sat, May 28, 2011 at 8:08 PM, sukhmeet singh sukhmeet2...@gmail.comwrote:

 don't see the online compiler.. it doesn't allow such a large array.. try
 on LINUX..
 this is the one I got a/c  on SPOJ ..!! http://ideone.com/NdBYJ


 On Sat, May 28, 2011 at 5:26 PM, Logic King crazy.logic.k...@gmail.comwrote:

 @sukhmeetyour code is having runtime error !!


 On Sat, May 28, 2011 at 4:48 AM, sukhmeet singh 
 sukhmeet2...@gmail.comwrote:

 follow what Akash said..!!
 in case you still need help just go through http://ideone.com/al0U0  in
 devcpp..!!

 On Sat, May 28, 2011 at 2:34 PM, Aakash Johari aakashj@gmail.comwrote:

 Precompute the values. and then do queries.


 On Sat, May 28, 2011 at 1:46 AM, Akshata Sharma 
 akshatasharm...@gmail.com wrote:

 My code gives TLE. What further optimization is required in my code??
 https://www.spoj.pl/problems/FACVSPOW/






 /*FACVSPOW*/
 #includestdio.h





 #includecmath






 using namespace std;






 int calc(long n, long a)





 {
  if(((n*log(n)-n)+0.5*log(2*M_PI*n)-n*log(a))=0)






  return 1;
  else return -1;





 }
 int main()





 {
 long t;
 scanf(%ld,t);





 long a;
 while(t--)





 {
  scanf(%ld,a);






  long lo=2*a;






  long hi=(long)(2.718281828*a) + 1;






  long mid;
  while(lohi)






  {
   mid=(lo+hi)/2;






   if(calc(mid,a)0)






   lo=mid+1
   else if(calc(mid,a)0)






   hi=mid;

   if(calc(mid,a)0  calc(mid-1,a)0)






   break;
  }
   printf(%ld\n,mid);





 }
 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.




 --
 -Aakash Johari
 (IIIT Allahabad)





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


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


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


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


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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 Help

2011-05-28 Thread sravanreddy001
Hi all. Can some one provide a good C editor.. preferable GUI one, that 
works on windows 7.

I'm good with Java, but. now would like to get some hands on C, C++

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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 Help

2011-05-23 Thread Akshata Sharma
@tec: the sequence should be like (0,1),(1,1),(1,2),(2,3),(3,5),(5,8)... or
m i wrong?

On Mon, May 23, 2011 at 11:08 AM, Aakash Johari aakashj@gmail.comwrote:

 Matrix exponentiation can help i think

 On Sun, May 22, 2011 at 10:36 PM, Akshata Sharma 
 akshatasharm...@gmail.com wrote:

 It appers that the problem is just to find the (N+3)th fibonacci number
 for given N. Since N is very large, how to find nth fibonaci number for such
 a large n??

 On Mon, May 23, 2011 at 7:51 AM, tec technic@gmail.com wrote:

 Try thinking backwards.
 (0,1),(1,2),(2,3),(3,5),(5,8),(8,13),...

 2011/5/22 shady sinv...@gmail.com:
  Hey,
  Can anyone tell how to solve this problem in Spoj ? I went through
  some material but there all they were discussing was on complexity and
  not on actual number of iterations.
  http://www.spoj.pl/problems/MAIN74/
 
  Thanks.
 
  --
  You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from 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.




 --
 -Aakash Johari
 (IIIT 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 Help

2011-05-23 Thread sravanreddy001
@akshata,
The (1,1) would be a special case.
for give N=1, but again for N=1, (2,1) also satisfies well.
And the series from then is constructed on the  (1,0), (2,1), (3,2) So and 
so.. 
Also if you see in the original problem statement, they mentioned a=b, but 
not ab..
this is for the special case, i.e, for N=1, the return value is 2 (1+1) and 
for other N value
its ( fib(N+3) + fib(N+2) ) 
 
@akash.. can you please point me to the matrix exponentiation method? I've 
no idea on this for this prob..
 

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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 Help

2011-05-23 Thread sravanreddy001
There is also another special case..  where N=0, in this case.. its (0,0) 
-- 0+0 = 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 Help

2011-05-23 Thread anshu mishra
@sravanreddy001
suppose u have to calulate A^n u can calculate in O(d^3*log(n));
d is dimesion of matrixl
while (n)
{
if (n1) mul(ans, A, d);
mul(A, A, d);
n =1;
}


-- 
Anshuman Mishra
IIIT Allahabad
-

anshumishra6...@gmail.com
rit2007...@iiita.ac.in

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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 Help

2011-05-23 Thread Akshata Sharma
@sravanreddy001
by matrix exponential method, we can calculate the nth fibonacci number in
logarithmic time.

On Mon, May 23, 2011 at 7:39 PM, anshu mishra anshumishra6...@gmail.comwrote:

 @sravanreddy001
 suppose u have to calulate A^n u can calculate in O(d^3*log(n));
 d is dimesion of matrixl
 while (n)
 {
 if (n1) mul(ans, A, d);
 mul(A, A, d);
 n =1;
 }


 --
 Anshuman Mishra
 IIIT Allahabad
 -

 anshumishra6...@gmail.com
 rit2007...@iiita.ac.in

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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 Help

2011-05-23 Thread Aakash Johari
@akshata, sravanreddy: yes, for more info regarding matrix expo. you can go
through http://zobayer.blogspot.com/2010/11/matrix-exponentiation.html

On Mon, May 23, 2011 at 7:28 AM, Akshata Sharma
akshatasharm...@gmail.comwrote:

 @sravanreddy001
 by matrix exponential method, we can calculate the nth fibonacci number in
 logarithmic time.


 On Mon, May 23, 2011 at 7:39 PM, anshu mishra 
 anshumishra6...@gmail.comwrote:

 @sravanreddy001
 suppose u have to calulate A^n u can calculate in O(d^3*log(n));
 d is dimesion of matrixl
 while (n)
 {
 if (n1) mul(ans, A, d);
 mul(A, A, d);
 n =1;
 }


 --
 Anshuman Mishra
 IIIT Allahabad
 -

 anshumishra6...@gmail.com
 rit2007...@iiita.ac.in

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




-- 
-Aakash Johari
(IIIT 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 Help

2011-05-23 Thread ankit sambyal
we can use the following formula to calculate the nth fibonacci no. in O(log
n) time : fib(n)=round((pow(phi,n))/sqrt(5) + 1/2)  where phi=(1+sqrt(5))/2;

And by taking care of the special cases and by using the fact that  the problem
is just to find the (N+3)th fibonacci number for given N, we can proceed





On Mon, May 23, 2011 at 8:17 AM, Aakash Johari aakashj@gmail.comwrote:

 @akshata, sravanreddy: yes, for more info regarding matrix expo. you can go
 through http://zobayer.blogspot.com/2010/11/matrix-exponentiation.html


 On Mon, May 23, 2011 at 7:28 AM, Akshata Sharma akshatasharm...@gmail.com
  wrote:

 @sravanreddy001
 by matrix exponential method, we can calculate the nth fibonacci number in
 logarithmic time.


 On Mon, May 23, 2011 at 7:39 PM, anshu mishra 
 anshumishra6...@gmail.comwrote:

 @sravanreddy001
 suppose u have to calulate A^n u can calculate in O(d^3*log(n));
 d is dimesion of matrixl
 while (n)
 {
 if (n1) mul(ans, A, d);
 mul(A, A, d);
 n =1;
 }


 --
 Anshuman Mishra
 IIIT Allahabad
 -

 anshumishra6...@gmail.com
 rit2007...@iiita.ac.in

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




 --
 -Aakash Johari
 (IIIT 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 Problem Help

2011-05-22 Thread shady
Hey,
Can anyone tell how to solve this problem in Spoj ? I went through
some material but there all they were discussing was on complexity and
not on actual number of iterations.
http://www.spoj.pl/problems/MAIN74/

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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 Help

2011-05-22 Thread tec
Try thinking backwards.
(0,1),(1,2),(2,3),(3,5),(5,8),(8,13),...

2011/5/22 shady sinv...@gmail.com:
 Hey,
 Can anyone tell how to solve this problem in Spoj ? I went through
 some material but there all they were discussing was on complexity and
 not on actual number of iterations.
 http://www.spoj.pl/problems/MAIN74/

 Thanks.

 --
 You received this message because you are subscribed to the Google Groups 
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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 Help

2011-05-22 Thread Akshata Sharma
It appers that the problem is just to find the (N+3)th fibonacci number for
given N. Since N is very large, how to find nth fibonaci number for such a
large n??

On Mon, May 23, 2011 at 7:51 AM, tec technic@gmail.com wrote:

 Try thinking backwards.
 (0,1),(1,2),(2,3),(3,5),(5,8),(8,13),...

 2011/5/22 shady sinv...@gmail.com:
  Hey,
  Can anyone tell how to solve this problem in Spoj ? I went through
  some material but there all they were discussing was on complexity and
  not on actual number of iterations.
  http://www.spoj.pl/problems/MAIN74/
 
  Thanks.
 
  --
  You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from 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 Help

2011-05-22 Thread Aakash Johari
Matrix exponentiation can help i think

On Sun, May 22, 2011 at 10:36 PM, Akshata Sharma
akshatasharm...@gmail.comwrote:

 It appers that the problem is just to find the (N+3)th fibonacci number for
 given N. Since N is very large, how to find nth fibonaci number for such a
 large n??

 On Mon, May 23, 2011 at 7:51 AM, tec technic@gmail.com wrote:

 Try thinking backwards.
 (0,1),(1,2),(2,3),(3,5),(5,8),(8,13),...

 2011/5/22 shady sinv...@gmail.com:
  Hey,
  Can anyone tell how to solve this problem in Spoj ? I went through
  some material but there all they were discussing was on complexity and
  not on actual number of iterations.
  http://www.spoj.pl/problems/MAIN74/
 
  Thanks.
 
  --
  You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from 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.




-- 
-Aakash Johari
(IIIT 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: HASHIT

2011-05-20 Thread ankit sambyal
Hey guys , I am getting wrong answer in  :
http://www.spoj.pl/problems/HASHIT/.   Somebdy plz check it out or provide
some test cases. This code works fine with the test cases provided and even
my own test cases.

The following is my code:

#includestdio.h
#includestring.h
int main()
{
int num_tcases,num_ops,i,j,k,l,n,x,m,y,count;
int occupied[101];
char table[101][16];
char temp[20],temp1[20];
scanf(%d,num_tcases);

for(x=0;xnum_tcases;x++)
{
count=0;
scanf(%d,num_ops);
for(i=0;i101;i++)
{
occupied[i]=0;
}
for(i=0;inum_ops;i++)
{
scanf(%s,temp);
n=0;
for(j=1;j=(strlen(temp)-4);j++)
{
n=n+j*temp[j+3];
}
n=19*n;
n=n%101;
y=n;
if(temp[0]=='A')
{
l=1;
  label: if(occupied[n]==0)
{
j=4;k=0;
while(temp[j]!='\0')
table[n][k++]=temp[j++];
table[n][k]='\0';
occupied[n]=1;
count++;
}
else if(occupied[n]==1)
{
temp1[0]='A';  temp1[1]='D';  temp1[2]='D';  temp1[3]=':';
m=0;
while(table[n][m]!='\0')
{
temp1[m+4]=table[n][m];
m++;
}
temp1[m+4]='\0';
//strcat(temp1,table[n]);
   //printf(\n%s,temp1);
if(strcmp(temp1,temp)!=0)
{
if(l20)
{
  n=y+l*l+23*l;
  n=n%101;
  l++;
  goto label;
}
}
}
}
else if(temp[0]=='D')
{
l=1;
label1: if(occupied[n]==0)
{
if(l=20)
{
  n=y+l*l+23*l;
  n=n%101;
  l++;
  goto label1;
}
}
else if(occupied[n]==1)
{
temp1[0]='D';  temp1[1]='E';  temp1[2]='L';  temp1[3]=':';
m=0;
while(table[n][m]!='\0')
{
temp1[m+4]=table[n][m];
m++;
}
temp1[m+4]='\0';
//strcat(temp1,table[n]);
//printf(\n%s,temp1);
if((strcmp(temp1,temp)!=0)  (occupied[n]==1))
{
if(l=20)
{
  n=y+l*l+23*l;
  n=n%101;
  l++;
  goto label1;
}
}
else if((strcmp(temp1,temp)==0)  (occupied[n]==1))
{
occupied[n]=0;
count--;
}
}

}
}

printf(\n%d,count);
for(i=0;i101;i++)
{
if(occupied[i]==1)
{
printf(\n%d:,i);
printf(%s,table[i]);
}
}
}
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.



[algogeeks] SPOJ Problem : PALIN

2011-03-28 Thread ankit sambyal
I m getting WA in this question though all the test cases are giving correct
output. Link to the problem : https://www.spoj.pl/problems/PALIN/
  Can anybdy check out my code . The following is my code :

#includestdio.h
#includestring.h

 int compare(char s[], char t[])
 {
//only check second half
int midpoint,i,l;
l=strlen(s);
midpoint = l / 2;
i = l % 2 == 0 ? midpoint : midpoint + 1;
for (; i  l; i++)
{
  if(s[i]  t[i])
  {
return -1 ;
  }
  else if (s[i]  t[i])
  {
return 1;
  }
}
return 0;
  }
void fun2(char str[])
{
int i,m,midpoint,l;
l=strlen(str);
midpoint=l/2;
i=l%2==0?midpoint:midpoint+1;
while (i  l)
{
  str[i] = str[midpoint - 1];
  i++;
  midpoint--;
}
}
void fun1(char arr[])
{
  int n,midpoint,currPoint,found,l;
  char c,inc;
  l=strlen(arr);
  char newarr[l + 1];

  midpoint = l / 2;
  currPoint=l%2==0?midpoint-1:midpoint;
  found = 0;
  while (currPoint = 0  found==0)
  {
c = arr[currPoint];
if (c == '9')
{
  inc = '0';
}
else
{
  inc = (char) (c + 1);
  found = 1;
}
arr[currPoint] = inc;
if (found==0)
{
  currPoint--;
}
  }

  if (found==0)
   {
// we have fallen off the start of the string
// example 999 has become 009. Add a one on to give: 1009
newarr[0]= '1';
newarr[1]='\0';
strcat(newarr,arr);
strcpy(arr,newarr);
  }
}

void fun(char str[])
{
char temp[101];
int m,midpoint,i,l;
l=strlen(str);
strcpy(temp,str);
midpoint=(int)(l/2);
i=l%2==0?midpoint:midpoint+1;
while (i  l)
{
  str[i] = str[midpoint - 1];
  i++;
  midpoint--;
}
if(compare(str,temp)==0 || compare(str,temp)==-1)
  {
  fun1(str);
  fun2(str);
  }
}


int main()
{
int t;
char str[102];
scanf(%d,t);
while(t0)
{
scanf(%s,str);
fun(str);
printf(%s,str);
t--;
}
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-BRCKTS

2011-03-26 Thread sukhmeet singh
Bharath can u tell me how u came with the combine function ??? I can't
understand the logic behind it ... do reply

On Wed, Mar 16, 2011 at 10:24 PM, Bharath 2009503507 CSE 
bharathgo...@gmail.com wrote:

 i am new to segment trees..i tried this problem in spoj..
 http://www.spoj.pl/problems/BRCKTS
 am getting WA..
 pls help...

 code:

 #includeiostream
 #includevector
 #includecstdio
 #includecmath
 #includestring
 using namespace std;
 class pi
 {
public:
int a,b;
pi(){a=0;b=0;}
pi(int x,int y) {a=x;b=y;}
 };
 vectorpi tree;
 string str;
 pi combine(pi a,pi b)
 {
pi x;
if(a.b==b.a)
{
x.a=a.a;
x.b=b.b;
}
else if(a.b  b.a)
{
x.a=a.a;
x.b=a.b-b.a+b.b;
}
else
{
x.b=b.b;
x.a=b.a-a.b+a.a;
}
return x;
 }
 void build(int node,int b,int e)
 {
if(b==e)
{
if(str[b]=='(')
{
tree[node].a=0;
tree[node].b=1;
}
else
{
tree[node].a=1;
tree[node].b=0;
}
return;
}
 //  coutnode\n;
int mid=(b+e)/2;
build(node*2,b,mid);
build(node*2+1,mid+1,e);
tree[node]=combine(tree[node*2],tree[node*2+1]);
 }
 void update(int node,int b,int e,int index)
 {
if(index  b || index e)  return;
if(b==e)
{
if(tree[node].a==1)
tree[node].a=0;
else
tree[node].a=1;
if(tree[node].b==1)
tree[node].b=0;
else
tree[node].b=1;
return;
}
int mid=(b+e)/2;
update(node*2,b,mid,index);
update(node*2+1,mid+1,e,index);
tree[node]=combine(tree[node*2],tree[node*2+1]);
 }
 main()
 {
for(int test=1;test=10;test++)
{
printf(Test %d:\n,test);
int n;
scanf(%d,n);
if(!n) continue;
int size=(1(int(log10(n)/log10(2))+2));
//  coutsize\n;
vectorpi temp(size);
tree=temp;
temp.clear();
string s;
cins;
str=s;
s.clear();
build(1,0,str.size()-1);
int x;
scanf(%d,x);
while(x--)
{
int k;
scanf(%d,k);
if(k==0)
{
if(!tree[1].a  !tree[1].b)
printf(Yes\n);
else
printf(No\n);
}
else
update(1,0,str.size()-1,k-1);
}
}

 }

 Thanks in advace..
  Bharath..

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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-BRCKTS

2011-03-26 Thread bharath kannan
i already mentioned the link where i got this approach..

//from spoj forum
I have tried this problem with the following approach:-
1. any expression can be expressed as ))...)+a_correct_expression+((...(
2.at each node i am storing 1.no_of ')' at start and 2.no_of '(' at end of
expression that the node is holding (ignoring the correct part)..
3.whenever u r merging two nodes to form its parent, it looks like
following:-
left_child[))...)((..(]++right_child[))..)((..(]
=))...)++((..())..)++((..(
=[))..)++))..)]++((..( OR, ))..)++[((..(++((..(]
i.e. comparing the no_of '(' in the left and no_of ')' in the right , u can
recalculate the no_of ')' and no_of '(' for the parent node)
4.for the leaf node, if the character is '(' =no_of '('=1 and no_of ')'=0,
otherwise just the opposite case
5.finally, if the whole expression is correct , there will be 0,0 entry in
the root node, otherwise whole expression is not correct...

i guess it explains all.. :)
On Sat, Mar 26, 2011 at 6:32 PM, sukhmeet singh sukhmeet2...@gmail.comwrote:

 Bharath can u tell me how u came with the combine function ??? I can't
 understand the logic behind it ... do reply

 On Wed, Mar 16, 2011 at 10:24 PM, Bharath 2009503507 CSE 
 bharathgo...@gmail.com wrote:

 i am new to segment trees..i tried this problem in spoj..
 http://www.spoj.pl/problems/BRCKTS
 am getting WA..
 pls help...

 code:

 #includeiostream
 #includevector
 #includecstdio
 #includecmath
 #includestring
 using namespace std;
 class pi
 {
public:
int a,b;
pi(){a=0;b=0;}
pi(int x,int y) {a=x;b=y;}
 };
 vectorpi tree;
 string str;
 pi combine(pi a,pi b)
 {
pi x;
if(a.b==b.a)
{
x.a=a.a;
x.b=b.b;
}
else if(a.b  b.a)
{
x.a=a.a;
x.b=a.b-b.a+b.b;
}
else
{
x.b=b.b;
x.a=b.a-a.b+a.a;
}
return x;
 }
 void build(int node,int b,int e)
 {
if(b==e)
{
if(str[b]=='(')
{
tree[node].a=0;
tree[node].b=1;
}
else
{
tree[node].a=1;
tree[node].b=0;
}
return;
}
 //  coutnode\n;
int mid=(b+e)/2;
build(node*2,b,mid);
build(node*2+1,mid+1,e);
tree[node]=combine(tree[node*2],tree[node*2+1]);
 }
 void update(int node,int b,int e,int index)
 {
if(index  b || index e)  return;
if(b==e)
{
if(tree[node].a==1)
tree[node].a=0;
else
tree[node].a=1;
if(tree[node].b==1)
tree[node].b=0;
else
tree[node].b=1;
return;
}
int mid=(b+e)/2;
update(node*2,b,mid,index);
update(node*2+1,mid+1,e,index);
tree[node]=combine(tree[node*2],tree[node*2+1]);
 }
 main()
 {
for(int test=1;test=10;test++)
{
printf(Test %d:\n,test);
int n;
scanf(%d,n);
if(!n) continue;
int size=(1(int(log10(n)/log10(2))+2));
//  coutsize\n;
vectorpi temp(size);
tree=temp;
temp.clear();
string s;
cins;
str=s;
s.clear();
build(1,0,str.size()-1);
int x;
scanf(%d,x);
while(x--)
{
int k;
scanf(%d,k);
if(k==0)
{
if(!tree[1].a  !tree[1].b)
printf(Yes\n);
else
printf(No\n);
}
else
update(1,0,str.size()-1,k-1);
}
}

 }

 Thanks in advace..
  Bharath..

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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 

Re: [algogeeks] SPOJ problem

2011-03-25 Thread sukhmeet singh
try using precomputation in a better way ...this got me AC.. rest is just
binary search function ...!!!

On Thu, Mar 24, 2011 at 9:06 PM, .bashrc saurab...@gmail.com wrote:

 Has anyone solved this problem-https://www.spoj.pl/problems/FACVSPOW/
 I am getting TLE using binary search.
 Thanks in advance

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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

2011-03-25 Thread saurabh singh
I am very sorry but i dont think i got your point.You suggesting
interpolation?
Kindly suggest some reference for good precomputation techniques..
Thanks in advance

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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

2011-03-24 Thread .bashrc
Has anyone solved this problem-https://www.spoj.pl/problems/FACVSPOW/
I am getting TLE using binary search.
Thanks in advance

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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-BRCKTS

2011-03-20 Thread murthy.krishn...@gmail.com
@anurag accor to me the output must be YES, correct me if I am wrong

On Sun, Mar 20, 2011 at 10:40 AM, bharath kannan bharathgo...@gmail.comwrote:

 i thot tat i had some mistake in my code and typed it all over again..
 finally i noticed this :)



 On Sat, Mar 19, 2011 at 12:12 AM, Kunal Patil kp101...@gmail.com wrote:

 Hey..
 I also got into same trouble today...
 I submitted it 6 times..then got bored and de moralised cause i cudnt find
 flaw in code...
 When i read your mail and corresponding sorry mail...it just struck me..I
 also had to print YES and NOand i was printing NO as NoIt
 got ac den...
 :P
 thnx anyway !!!

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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-BRCKTS

2011-03-20 Thread bharath kannan
@murthy:no..the op must be NOits not a valid expression..read the two
conditions for a valid expression..

On Sun, Mar 20, 2011 at 8:23 PM, murthy.krishn...@gmail.com 
murthy.krishn...@gmail.com wrote:

 @anurag accor to me the output must be YES, correct me if I am wrong


 On Sun, Mar 20, 2011 at 10:40 AM, bharath kannan 
 bharathgo...@gmail.comwrote:

 i thot tat i had some mistake in my code and typed it all over again..
 finally i noticed this :)



 On Sat, Mar 19, 2011 at 12:12 AM, Kunal Patil kp101...@gmail.com wrote:

 Hey..
 I also got into same trouble today...
 I submitted it 6 times..then got bored and de moralised cause i cudnt
 find flaw in code...
 When i read your mail and corresponding sorry mail...it just struck me..I
 also had to print YES and NOand i was printing NO as NoIt
 got ac den...
 :P
 thnx anyway !!!

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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-BRCKTS

2011-03-20 Thread murthy.krishn...@gmail.com
@bharath yaa now I got the ques, thanx :-)

On Mon, Mar 21, 2011 at 4:47 AM, bharath kannan bharathgo...@gmail.comwrote:

 @murthy:no..the op must be NOits not a valid expression..read the two
 conditions for a valid expression..

 On Sun, Mar 20, 2011 at 8:23 PM, murthy.krishn...@gmail.com 
 murthy.krishn...@gmail.com wrote:

 @anurag accor to me the output must be YES, correct me if I am wrong


 On Sun, Mar 20, 2011 at 10:40 AM, bharath kannan 
 bharathgo...@gmail.comwrote:

 i thot tat i had some mistake in my code and typed it all over again..
 finally i noticed this :)



 On Sat, Mar 19, 2011 at 12:12 AM, Kunal Patil kp101...@gmail.comwrote:

 Hey..
 I also got into same trouble today...
 I submitted it 6 times..then got bored and de moralised cause i cudnt
 find flaw in code...
 When i read your mail and corresponding sorry mail...it just struck
 me..I also had to print YES and NOand i was printing NO as
 NoIt got ac den...
 :P
 thnx anyway !!!

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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-BRCKTS

2011-03-20 Thread Anurag atri
@krishna - yeah as Bharath said that case should give NO , anyways you got
it now :)

On Mon, Mar 21, 2011 at 5:50 AM, murthy.krishn...@gmail.com 
murthy.krishn...@gmail.com wrote:

 @bharath yaa now I got the ques, thanx :-)


 On Mon, Mar 21, 2011 at 4:47 AM, bharath kannan bharathgo...@gmail.comwrote:

 @murthy:no..the op must be NOits not a valid expression..read the two
 conditions for a valid expression..

 On Sun, Mar 20, 2011 at 8:23 PM, murthy.krishn...@gmail.com 
 murthy.krishn...@gmail.com wrote:

 @anurag accor to me the output must be YES, correct me if I am wrong


 On Sun, Mar 20, 2011 at 10:40 AM, bharath kannan bharathgo...@gmail.com
  wrote:

 i thot tat i had some mistake in my code and typed it all over again..
 finally i noticed this :)



 On Sat, Mar 19, 2011 at 12:12 AM, Kunal Patil kp101...@gmail.comwrote:

 Hey..
 I also got into same trouble today...
 I submitted it 6 times..then got bored and de moralised cause i cudnt
 find flaw in code...
 When i read your mail and corresponding sorry mail...it just struck
 me..I also had to print YES and NOand i was printing NO as
 NoIt got ac den...
 :P
 thnx anyway !!!

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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
Anurag Atri

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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-BRCKTS

2011-03-20 Thread murthy.krishn...@gmail.com
Thanks 2 all

On Mon, Mar 21, 2011 at 9:19 AM, Anurag atri anu.anurag@gmail.comwrote:

 @krishna - yeah as Bharath said that case should give NO , anyways you got
 it now :)


 On Mon, Mar 21, 2011 at 5:50 AM, murthy.krishn...@gmail.com 
 murthy.krishn...@gmail.com wrote:

 @bharath yaa now I got the ques, thanx :-)


 On Mon, Mar 21, 2011 at 4:47 AM, bharath kannan 
 bharathgo...@gmail.comwrote:

 @murthy:no..the op must be NOits not a valid expression..read the two
 conditions for a valid expression..

 On Sun, Mar 20, 2011 at 8:23 PM, murthy.krishn...@gmail.com 
 murthy.krishn...@gmail.com wrote:

 @anurag accor to me the output must be YES, correct me if I am wrong


 On Sun, Mar 20, 2011 at 10:40 AM, bharath kannan 
 bharathgo...@gmail.com wrote:

 i thot tat i had some mistake in my code and typed it all over again..
 finally i noticed this :)



 On Sat, Mar 19, 2011 at 12:12 AM, Kunal Patil kp101...@gmail.comwrote:

 Hey..
 I also got into same trouble today...
 I submitted it 6 times..then got bored and de moralised cause i cudnt
 find flaw in code...
 When i read your mail and corresponding sorry mail...it just struck
 me..I also had to print YES and NOand i was printing NO as
 NoIt got ac den...
 :P
 thnx anyway !!!

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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
 Anurag Atri

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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- TRICOUNT

2011-03-19 Thread cegprakash
Here is my code for TRICOUNT problem

//http://www.spoj.pl/problems/TRICOUNT/
//cegprak...@gmail.com

#includeiostream
#includeconio.h
using namespace std;
unsigned long long start,end,arr[101],arr2[101];
//number of triangles facing upwards=arr
//number of triangles facing downwards=arr2

int main(){
int j,t,i,n;
for(i=0;i1;i++){
arr[i]=i+1+arr[i-1];
}
for(i=0;i1;i++)
{
arr[i]+=arr[i-1];
}
arr2[1]=1;
for(i=2;i=1;i++){
 arr2[i]=0;
 for(end=i;;end=end-2){
  arr2[i]+=end*(end+1)/2;
  if(end=2) break;
 }
}
cint;
while(t--){
 cinn;
 coutarr[n-1]+arr2[n-1]endl;
}



return 0;
}


my algorithm is fast upto input value of 10^4. i donno why my
algorithm doesn't satisfy 10^6
someone 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 problem- TRICOUNT

2011-03-19 Thread sukhmeet singh
may be u can try to find a more general formula for the series..which just
depends on 'n'...

On Sat, Mar 19, 2011 at 11:48 PM, cegprakash cegprak...@gmail.com wrote:

 Here is my code for TRICOUNT problem

 //http://www.spoj.pl/problems/TRICOUNT/
 //cegprak...@gmail.com

 #includeiostream
 #includeconio.h
 using namespace std;
 unsigned long long start,end,arr[101],arr2[101];
 //number of triangles facing upwards=arr
 //number of triangles facing downwards=arr2

 int main(){
int j,t,i,n;
for(i=0;i1;i++){
arr[i]=i+1+arr[i-1];
}
for(i=0;i1;i++)
{
arr[i]+=arr[i-1];
}
arr2[1]=1;
for(i=2;i=1;i++){
 arr2[i]=0;
 for(end=i;;end=end-2){
  arr2[i]+=end*(end+1)/2;
  if(end=2) break;
 }
}
cint;
while(t--){
 cinn;
 coutarr[n-1]+arr2[n-1]endl;
}



return 0;
 }


 my algorithm is fast upto input value of 10^4. i donno why my
 algorithm doesn't satisfy 10^6
 someone 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.



Re: [algogeeks] SPOJ problem-BRCKTS

2011-03-19 Thread bharath kannan
i thot tat i had some mistake in my code and typed it all over again..
finally i noticed this :)


On Sat, Mar 19, 2011 at 12:12 AM, Kunal Patil kp101...@gmail.com wrote:

 Hey..
 I also got into same trouble today...
 I submitted it 6 times..then got bored and de moralised cause i cudnt find
 flaw in code...
 When i read your mail and corresponding sorry mail...it just struck me..I
 also had to print YES and NOand i was printing NO as NoIt
 got ac den...
 :P
 thnx anyway !!!

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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 : PRIME1

2011-03-18 Thread samby
The problem goes like this :
Peter wants to generate some prime numbers. Your task is to generate
all prime numbers between two given numbers!

Input
The input begins with the number t of test cases in a single line
(t=10). In each of the next t lines there are two numbers m and n (1
= m = n = 10, n-m=10) separated by a space.

Output
For every test case print all prime numbers p such that m = p = n,
one number per line, test cases separated by an empty line.

Example
Input:
2
1 10
3 5

Output:
2
3
5
7

3
5



the following is my code :
int main()
{
int t,trialdiv,a1,b1,i,j,candidate,flag,a[10],b[10];
scanf(%d,t);
for(i=0;it;i++)
{
scanf(\n%d %d,a[i],b[i]);
}
for(i=0;it;i++)
{
a1=a[i];  b1=b[i];
for(candidate=a1;candidate=b1;candidate++)
{
flag=1;
for(trialdiv=2;(trialdiv*trialdiv)=candidate;trialdiv++)
{
if((candidate % trialdiv) == 0)
{
flag = 0;
break;
}
}
if(flag==1  candidate != 1)
printf(\n%d,candidate);
}

printf(\n);
}
return 0;
}

I AM GETTING TIME LIMIT EXCEEDED. CAN ANYBODY HELP ME WITH AN
EFFICIENT ALGORITHM ??

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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 : PRIME1

2011-03-18 Thread Anurag atri
you should try sieve of eratosthenes

http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

there are far more efficient algorithms but i think this shoild be a good
one to start with . ( even i got AC with this one :)  )
On Fri, Mar 18, 2011 at 10:11 PM, samby ankitsamb...@gmail.com wrote:

 The problem goes like this :
 Peter wants to generate some prime numbers. Your task is to generate
 all prime numbers between two given numbers!

 Input
 The input begins with the number t of test cases in a single line
 (t=10). In each of the next t lines there are two numbers m and n (1
 = m = n = 10, n-m=10) separated by a space.

 Output
 For every test case print all prime numbers p such that m = p = n,
 one number per line, test cases separated by an empty line.

 Example
 Input:
 2
 1 10
 3 5

 Output:
 2
 3
 5
 7

 3
 5



 the following is my code :
 int main()
 {
int t,trialdiv,a1,b1,i,j,candidate,flag,a[10],b[10];
scanf(%d,t);
for(i=0;it;i++)
{
scanf(\n%d %d,a[i],b[i]);
}
for(i=0;it;i++)
{
a1=a[i];  b1=b[i];
for(candidate=a1;candidate=b1;candidate++)
{
flag=1;
for(trialdiv=2;(trialdiv*trialdiv)=candidate;trialdiv++)
{
if((candidate % trialdiv) == 0)
{
flag = 0;
break;
}
}
if(flag==1  candidate != 1)
printf(\n%d,candidate);
}

printf(\n);
}
return 0;
 }

 I AM GETTING TIME LIMIT EXCEEDED. CAN ANYBODY HELP ME WITH AN
 EFFICIENT ALGORITHM ??

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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
Anurag Atri

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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-BRCKTS

2011-03-18 Thread Kunal Patil
Hey..
I also got into same trouble today...
I submitted it 6 times..then got bored and de moralised cause i cudnt find
flaw in code...
When i read your mail and corresponding sorry mail...it just struck me..I
also had to print YES and NOand i was printing NO as NoIt
got ac den...
:P
thnx anyway !!!

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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-BRCKTS

2011-03-17 Thread bharath kannan
sorry guyz...
Had to print YES n NO..
i printed as Yes n No...
Got ac..
Sorry for the trouble..

On Wed, Mar 16, 2011 at 10:24 PM, Bharath 2009503507 CSE 
bharathgo...@gmail.com wrote:

 i am new to segment trees..i tried this problem in spoj..
 http://www.spoj.pl/problems/BRCKTS
 am getting WA..
 pls help...

 code:

 #includeiostream
 #includevector
 #includecstdio
 #includecmath
 #includestring
 using namespace std;
 class pi
 {
public:
int a,b;
pi(){a=0;b=0;}
pi(int x,int y) {a=x;b=y;}
 };
 vectorpi tree;
 string str;
 pi combine(pi a,pi b)
 {
pi x;
if(a.b==b.a)
{
x.a=a.a;
x.b=b.b;
}
else if(a.b  b.a)
{
x.a=a.a;
x.b=a.b-b.a+b.b;
}
else
{
x.b=b.b;
x.a=b.a-a.b+a.a;
}
return x;
 }
 void build(int node,int b,int e)
 {
if(b==e)
{
if(str[b]=='(')
{
tree[node].a=0;
tree[node].b=1;
}
else
{
tree[node].a=1;
tree[node].b=0;
}
return;
}
 //  coutnode\n;
int mid=(b+e)/2;
build(node*2,b,mid);
build(node*2+1,mid+1,e);
tree[node]=combine(tree[node*2],tree[node*2+1]);
 }
 void update(int node,int b,int e,int index)
 {
if(index  b || index e)  return;
if(b==e)
{
if(tree[node].a==1)
tree[node].a=0;
else
tree[node].a=1;
if(tree[node].b==1)
tree[node].b=0;
else
tree[node].b=1;
return;
}
int mid=(b+e)/2;
update(node*2,b,mid,index);
update(node*2+1,mid+1,e,index);
tree[node]=combine(tree[node*2],tree[node*2+1]);
 }
 main()
 {
for(int test=1;test=10;test++)
{
printf(Test %d:\n,test);
int n;
scanf(%d,n);
if(!n) continue;
int size=(1(int(log10(n)/log10(2))+2));
//  coutsize\n;
vectorpi temp(size);
tree=temp;
temp.clear();
string s;
cins;
str=s;
s.clear();
build(1,0,str.size()-1);
int x;
scanf(%d,x);
while(x--)
{
int k;
scanf(%d,k);
if(k==0)
{
if(!tree[1].a  !tree[1].b)
printf(Yes\n);
else
printf(No\n);
}
else
update(1,0,str.size()-1,k-1);
}
}

 }

 Thanks in advace..
  Bharath..

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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-BRCKTS

2011-03-16 Thread Bharath 2009503507 CSE
i am new to segment trees..i tried this problem in spoj..
http://www.spoj.pl/problems/BRCKTS
am getting WA..
pls help...

code:

#includeiostream
#includevector
#includecstdio
#includecmath
#includestring
using namespace std;
class pi
{
public:
int a,b;
pi(){a=0;b=0;}
pi(int x,int y) {a=x;b=y;}
};
vectorpi tree;
string str;
pi combine(pi a,pi b)
{
pi x;
if(a.b==b.a)
{
x.a=a.a;
x.b=b.b;
}
else if(a.b  b.a)
{
x.a=a.a;
x.b=a.b-b.a+b.b;
}
else
{
x.b=b.b;
x.a=b.a-a.b+a.a;
}
return x;
}
void build(int node,int b,int e)
{
if(b==e)
{
if(str[b]=='(')
{
tree[node].a=0;
tree[node].b=1;
}
else
{
tree[node].a=1;
tree[node].b=0;
}
return;
}
//  coutnode\n;
int mid=(b+e)/2;
build(node*2,b,mid);
build(node*2+1,mid+1,e);
tree[node]=combine(tree[node*2],tree[node*2+1]);
}
void update(int node,int b,int e,int index)
{
if(index  b || index e)  return;
if(b==e)
{
if(tree[node].a==1)
tree[node].a=0;
else
tree[node].a=1;
if(tree[node].b==1)
tree[node].b=0;
else
tree[node].b=1;
return;
}
int mid=(b+e)/2;
update(node*2,b,mid,index);
update(node*2+1,mid+1,e,index);
tree[node]=combine(tree[node*2],tree[node*2+1]);
}
main()
{
for(int test=1;test=10;test++)
{
printf(Test %d:\n,test);
int n;
scanf(%d,n);
if(!n) continue;
int size=(1(int(log10(n)/log10(2))+2));
//  coutsize\n;
vectorpi temp(size);
tree=temp;
temp.clear();
string s;
cins;
str=s;
s.clear();
build(1,0,str.size()-1);
int x;
scanf(%d,x);
while(x--)
{
int k;
scanf(%d,k);
if(k==0)
{
if(!tree[1].a  !tree[1].b)
printf(Yes\n);
else
printf(No\n);
}
else
update(1,0,str.size()-1,k-1);
}
}

}

Thanks in advace..
 Bharath..

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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

2011-03-15 Thread UTKARSH SRIVASTAV
well i have a doubt the test case says number could be as large as
10 and you have taken int but int does not have such range then how
it is accepted

On Sat, Mar 12, 2011 at 7:57 PM, Logic King crazy.logic.k...@gmail.comwrote:

 Here is my solution.i got it AC

 #includestdio.h
 int gcd(int a, int b)
 {   int temp;
while(b)
{
temp = a % b;
a = b;
b = temp;
}
 return(a);
 }

 int main()
 {
int n,i,min,ans=0;
scanf(%d,n);
int arr[n],ard[n];
ard[0]=1;
if(n0)
scanf(%d,arr[0]);
for(i=1;in;i++)
{
scanf(%d,arr[i]);
ard[i]=arr[i]-arr[i-1];
if(i==1)
min=ard[i];
else
min=gcd(min,ard[i]);

}
for(i=1;in;i++)
{
ans+=((ard[i]/min)-1);
}
printf(%d,ans);
 return 0;

 }



 On Sat, Mar 12, 2011 at 7:37 PM, Balaji Ramani 
 rbalaji.psgt...@gmail.comwrote:

 Yeah, I too am wondering how to implement more efficiently.


 On Sat, Mar 12, 2011 at 7:36 PM, Satyam Kapoor 
 satyamkapoo...@gmail.comwrote:



 @balaji:i hve got ac with gcd method but the time is 0.32 sec
  best soln is 0.03
 how is that achievable?
 --
 Satyam Kapoor
 B.Tech 2nd year
 Computer Science And Engineering
 M.N.N.I.T ALLAHABAD

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


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


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




-- 
*UTKARSH SRIVATAV*
*CSE-3
B-Tech 2nd 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

2011-03-15 Thread Logic King
i Agree.the test cases for which problem is being jugdged might not have
those larger values.


On Tue, Mar 15, 2011 at 12:20 PM, UTKARSH SRIVASTAV usrivastav...@gmail.com
 wrote:

 well i have a doubt the test case says number could be as large as
 10 and you have taken int but int does not have such range then how
 it is accepted


 On Sat, Mar 12, 2011 at 7:57 PM, Logic King crazy.logic.k...@gmail.comwrote:

 Here is my solution.i got it AC

 #includestdio.h
 int gcd(int a, int b)
 {   int temp;
while(b)
{
temp = a % b;
a = b;
b = temp;
}
 return(a);
 }

 int main()
 {
int n,i,min,ans=0;
scanf(%d,n);
int arr[n],ard[n];
ard[0]=1;
if(n0)
scanf(%d,arr[0]);
for(i=1;in;i++)
{
scanf(%d,arr[i]);
ard[i]=arr[i]-arr[i-1];
if(i==1)
min=ard[i];
else
min=gcd(min,ard[i]);

}
for(i=1;in;i++)
{
ans+=((ard[i]/min)-1);
}
printf(%d,ans);
 return 0;

 }



 On Sat, Mar 12, 2011 at 7:37 PM, Balaji Ramani rbalaji.psgt...@gmail.com
  wrote:

 Yeah, I too am wondering how to implement more efficiently.


 On Sat, Mar 12, 2011 at 7:36 PM, Satyam Kapoor satyamkapoo...@gmail.com
  wrote:



 @balaji:i hve got ac with gcd method but the time is 0.32 sec
  best soln is 0.03
 how is that achievable?
 --
 Satyam Kapoor
 B.Tech 2nd year
 Computer Science And Engineering
 M.N.N.I.T ALLAHABAD

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


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


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




 --
 *UTKARSH SRIVATAV*
 *CSE-3
 B-Tech 2nd 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 problem

2011-03-15 Thread Ankur Khurana
@utraksh : 10^9 is well in int limits

On Tue, Mar 15, 2011 at 12:56 PM, Satyam Kapoor satyamkapoo...@gmail.comwrote:

 @utkarsh:teri kismat acchi thi aur kuch nhimaze kar!

 ---
 Satyam Kapoor
 B.Tech-2nd 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 Problem

2011-03-15 Thread Balaji Ramani
It fails for input 1,2,3. I think there needs to be one more iteration to
check if the candidate is actually a majority element or not.

Thanks,
Balaji.



On Tue, Mar 15, 2011 at 9:50 PM, UTKARSH SRIVASTAV
usrivastav...@gmail.comwrote:


 CAN ANYONE PLEASE TELL ME WHY MY CODE IS GIVING WRONG ANSWER OR SOMEONE WHO
 HAS GOT AC IN THIS PROBLEM MAY POST HIS SOLUTION

 #includestdio.h
 main()
 {
 long long int n,t,r,count,major,i;
 scanf(%lld,t);
 while(t--)
 {
 scanf(%lld,n);
 scanf(%lld,r);
 major=r;
 count=1;
 for(i=1;in;i++)
 {
 scanf(%lld,r);
 if(r!=major)
 {
 count--;
 if(count0)
 {count=1;
 major=r;
 }
 }
 else
 {
 count++;
 }
 }
 if(count=0)
 printf(NO\n);
 else
 printf(YES%lld\n,major);
 }
 return 0;
 }





 --
 *UTKARSH SRIVATAV*
 *CSE-3
 B-Tech 2nd 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 Problem

2011-03-15 Thread Akshata Sharma
hey link to the problem??

On Tue, Mar 15, 2011 at 10:50 PM, Balaji Ramani
rbalaji.psgt...@gmail.comwrote:

 It fails for input 1,2,3. I think there needs to be one more iteration to
 check if the candidate is actually a majority element or not.

 Thanks,
 Balaji.




 On Tue, Mar 15, 2011 at 9:50 PM, UTKARSH SRIVASTAV 
 usrivastav...@gmail.com wrote:


 CAN ANYONE PLEASE TELL ME WHY MY CODE IS GIVING WRONG ANSWER OR SOMEONE
 WHO HAS GOT AC IN THIS PROBLEM MAY POST HIS SOLUTION

 #includestdio.h
 main()
 {
 long long int n,t,r,count,major,i;
 scanf(%lld,t);
 while(t--)
 {
 scanf(%lld,n);
 scanf(%lld,r);
 major=r;
 count=1;
 for(i=1;in;i++)
 {
 scanf(%lld,r);
 if(r!=major)
 {
 count--;
 if(count0)
 {count=1;
 major=r;
 }
 }
 else
 {
 count++;
 }
 }
 if(count=0)
 printf(NO\n);
 else
 printf(YES%lld\n,major);
 }
 return 0;
 }





 --
 *UTKARSH SRIVATAV*
 *CSE-3
 B-Tech 2nd 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.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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

2011-03-15 Thread Balaji Ramani
http://www.spoj.pl/problems/MAJOR/

http://www.spoj.pl/problems/MAJOR/Thanks,
Balaji.

On Tue, Mar 15, 2011 at 11:00 PM, Akshata Sharma
akshatasharm...@gmail.comwrote:

 hey link to the problem??


 On Tue, Mar 15, 2011 at 10:50 PM, Balaji Ramani rbalaji.psgt...@gmail.com
  wrote:

 It fails for input 1,2,3. I think there needs to be one more iteration to
 check if the candidate is actually a majority element or not.

 Thanks,
 Balaji.




 On Tue, Mar 15, 2011 at 9:50 PM, UTKARSH SRIVASTAV 
 usrivastav...@gmail.com wrote:


 CAN ANYONE PLEASE TELL ME WHY MY CODE IS GIVING WRONG ANSWER OR SOMEONE
 WHO HAS GOT AC IN THIS PROBLEM MAY POST HIS SOLUTION

 #includestdio.h
 main()
 {
 long long int n,t,r,count,major,i;
 scanf(%lld,t);
 while(t--)
 {
 scanf(%lld,n);
 scanf(%lld,r);
 major=r;
 count=1;
 for(i=1;in;i++)
 {
 scanf(%lld,r);
 if(r!=major)
 {
 count--;
 if(count0)
 {count=1;
 major=r;
 }
 }
 else
 {
 count++;
 }
 }
 if(count=0)
 printf(NO\n);
 else
 printf(YES%lld\n,major);
 }
 return 0;
 }





 --
 *UTKARSH SRIVATAV*
 *CSE-3
 B-Tech 2nd 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.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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

2011-03-15 Thread UTKARSH SRIVASTAV
tahnks balaji i have got ac in this problem my prog is same only in
the end i have taken a loop and
@ akshata the link for the prob is https://www.spoj.pl/problems/MAJOR/
MY CODE IS
#includestdio.h
main()
{
long long int n,t,r[100],count,major,i;
scanf(%lld,t);
while(t--)
{
scanf(%lld,n);
scanf(%lld,r[0]);
major=r[0];
count=1;
for(i=1;in;i++)
{
scanf(%lld,r[i]);
if(r[i]!=major)
{
count--;
if(count0)
{count=1;
major=r[i];
}
}
else
{
count++;
}
}
/*if(count=0)
printf(NO\n);
else
printf(YES%lld\n,major);*/
   count=0;
for(i=0;in;i++)
{
if(r[i]==major)
count++;
}
if(countn/2)
printf(YES %lld\n,major);
else
printf(NO\n);
}
scanf(%lld,r[0]);
return 0;
}

On Tue, Mar 15, 2011 at 10:34 AM, Balaji Ramani
rbalaji.psgt...@gmail.comwrote:

 http://www.spoj.pl/problems/MAJOR/

 http://www.spoj.pl/problems/MAJOR/Thanks,
 Balaji.


 On Tue, Mar 15, 2011 at 11:00 PM, Akshata Sharma 
 akshatasharm...@gmail.com wrote:

 hey link to the problem??


 On Tue, Mar 15, 2011 at 10:50 PM, Balaji Ramani 
 rbalaji.psgt...@gmail.com wrote:

 It fails for input 1,2,3. I think there needs to be one more iteration to
 check if the candidate is actually a majority element or not.

 Thanks,
 Balaji.




 On Tue, Mar 15, 2011 at 9:50 PM, UTKARSH SRIVASTAV 
 usrivastav...@gmail.com wrote:


 CAN ANYONE PLEASE TELL ME WHY MY CODE IS GIVING WRONG ANSWER OR SOMEONE
 WHO HAS GOT AC IN THIS PROBLEM MAY POST HIS SOLUTION

 #includestdio.h
 main()
 {
 long long int n,t,r,count,major,i;
 scanf(%lld,t);
 while(t--)
 {
 scanf(%lld,n);
 scanf(%lld,r);
 major=r;
 count=1;
 for(i=1;in;i++)
 {
 scanf(%lld,r);
 if(r!=major)
 {
 count--;
 if(count0)
 {count=1;
 major=r;
 }
 }
 else
 {
 count++;
 }
 }
 if(count=0)
 printf(NO\n);
 else
 printf(YES%lld\n,major);
 }
 return 0;
 }





 --
 *UTKARSH SRIVATAV*
 *CSE-3
 B-Tech 2nd 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.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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 SRIVATAV*
*CSE-3
B-Tech 2nd 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.



  1   2   >