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á 
Homepage  |
Maratona|
*




On Fri, Sep 28, 2012 at 6:17 PM, icy`  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.

<>

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.

<>

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 wrote:

> 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á 
> Homepage  | 
> Maratona|
> *
>
>
>
>
>
> On Thu, Sep 27, 2012 at 8:57 AM, atul anand 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 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.
>

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




On Thu, Sep 27, 2012 at 8:57 AM, atul anand  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  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-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  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 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-26 Thread atul anand
EXAMPLE 1)

1 10 2 2

a,d=2
a,a+d,a+2d,a+3d,a+4d are all multiple of 2 , so basically you need to
count elements which are multiple of 2 and then subtract from the 1-10
range(inclusive)

number of elements multiple of of 2 = (m/2) = 10/2 = 5
range = ( m - n) + 1 = 10

number of elements not multiple of 2 = range -  5 = 10 - 5 = 5(ans)

EXAMPLE 2)

20 100 3 3

a,d=3

same as above case a,a+d,a+2d,a+3d,a+4d all are multiple of 3

number of elements multiple of of 3(1..to..100) = (m/2) = 100/3 = 33
now 33 includes elements which lies b/w 1-19 , but we dont want those count
so remove those count..

number of elements multiple of of 3(1..to..19) =(n-1)/2 = (19/2) = 6
desired count lies b/w range (20-100) = 33 - 6 = 27
range = ( m - n) + 1 = 81

number of elements not multiple of 3 = range -  27 = 81 - 27 = 54 (ans)

so we just applying general formula :-
n(A U B) =n(A) + n(B) - n(A intersection B)

but in above 2 examples both a and d were same or could be multiple of
each otherthis is a simple scenario .

EXAMPLE 3)

20 100 2 3
suppose a = 2 , d = 3
now i am considering only a and a+d ...just to give you the idea..
so we need to find elments b/w 20-100 not divisible by 2 and 5.

using same method as above :-
elements divisible by 2 = 41
elements divisible by 5 = 17
total elements = 41 + 17 = 58

but some number are include twice in 58 number which are multiple
of both 2 and 5 i.e once by calculating counts for 2 and another while
calculating count for 5.
eg 10 = 5 x 2 , 20 = 4 x 5...etc..

so now we want to remove these double inclusion i.e calculating n(A
intersecting B).

which is nothing but same as counting elements divisible by ( a X a+d
) i.e 2 X 5 =10
by same method :-

elements divisible by 10 = 9
correct count of elements in range (20-100) = 58 - 9 = 49

number of elements not multiple of 2 or 5 = 81 - 49 = 32 (ANS)

now i hope you got the idea

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



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 wrote:

> use " return (a/gcd(a,b)*b instead "
>
>
> On Sun, Jun 24, 2012 at 7:10 PM, Sourabh Singh 
> wrote:
>
>> 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 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 wrote:

> 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 :STAMPS

2012-06-22 Thread Pradip Singh
use if(sum  wrote:

> @MAYANK your output format is wrong.use printf("\nScenario #%d:\n",(i+1));
> and
> if(sum   On Thu, Jun 21, 2012 at 12:34 PM, Mayank Singh <
> singh13490may...@gmail.com> wrote:
>
>> here is my code
>> /*#include
>> #include
>>
>> int main()
>> {
>> int cand,sum;
>> int T,N,i,j,temp[10];
>> scanf("%d",&T);
>>
>> sum = 0;
>> for(i=0;i> {
>> scanf("%d",&N);
>> for(j=0;j> {
>> scanf("%d",&cand);
>> sum = (sum+cand)%N;
>> }
>> if(sum == 0)
>> temp[i]=1;
>> else
>> temp[i]=0;
>> }
>> for(i=0;i> {
>> if(temp[i]==1)
>> printf("YES\n");
>> else
>> printf("NO\n");
>> }
>> return 0;
>> }*/
>>
>> #include
>> #include
>>
>> int main()
>> {
>> int t,frd,i,j,arr[1],sum,k,arr1[10],p;
>> scanf("%d",&t);
>> long int sta;
>> for(i=0;i> {
>> scanf("%ld",&sta);
>> scanf("%d",&frd);
>> for(j=0;j> {
>> scanf("%d",&arr[j]);
>> }
>> for(j=0;j> {
>>   for(k=0;k> {
>> if(arr[k]>   {
>>   sum = arr[k];
>> arr[k] = arr[k+1];
>> arr[k+1] = sum;
>>   }
>> }
>> }
>>
>> sum = 0;
>> p=0;
>> for(k=0;k> {
>> if(sum <= sta)
>> {
>> sum = sum+arr[k];
>> p++;
>> }
>> else
>> break;
>> }
>> if(sum < sta)
>> arr1[i] = 0;
>> else
>> arr1[i] = p;
>> }
>> for(i=0;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 :STAMPS

2012-06-22 Thread Pradip Singh
@MAYANK your output format is wrong.use printf("\nScenario #%d:\n",(i+1));
and
if(sum wrote:

> here is my code
> /*#include
> #include
>
> int main()
> {
> int cand,sum;
> int T,N,i,j,temp[10];
> scanf("%d",&T);
>
> sum = 0;
> for(i=0;i {
> scanf("%d",&N);
> for(j=0;j {
> scanf("%d",&cand);
> sum = (sum+cand)%N;
> }
> if(sum == 0)
> temp[i]=1;
> else
> temp[i]=0;
> }
> for(i=0;i {
> if(temp[i]==1)
> printf("YES\n");
> else
> printf("NO\n");
> }
> return 0;
> }*/
>
> #include
> #include
>
> int main()
> {
> int t,frd,i,j,arr[1],sum,k,arr1[10],p;
> scanf("%d",&t);
> long int sta;
> for(i=0;i {
> scanf("%ld",&sta);
> scanf("%d",&frd);
> for(j=0;j {
> scanf("%d",&arr[j]);
> }
> for(j=0;j {
>   for(k=0;k {
> if(arr[k]   {
>   sum = arr[k];
> arr[k] = arr[k+1];
> arr[k+1] = sum;
>   }
> }
> }
>
> sum = 0;
> p=0;
> for(k=0;k {
> if(sum <= sta)
> {
> sum = sum+arr[k];
> p++;
> }
> else
> break;
> }
> if(sum < sta)
> arr1[i] = 0;
> else
> arr1[i] = p;
> }
> for(i=0;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 : 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
wrote:

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



Re: [algogeeks] SPOJ problem : CANDY III

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



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"  wrote:

> here is my code :
>
> #include
> #include
>
> 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;i {
> scanf("%d",&N);
> for(j=0;j {
> scanf("%lld",&cand);
> sum = (sum+cand)%N;
> }
> if(sum == 0)
> temp[i]=1;
> else
> temp[i]=0;
> }
> for(i=0;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

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.



Re: [algogeeks] SPOJ problem : CANDY

2012-06-21 Thread Mayank Singh
my code is running perfectly well but giving WA in spoj..
#include
#include

int main()
{
int cand,sum;
int T,N,i,j,temp[10];
scanf("%d",&T);

sum = 0;
for(i=0;ihttp://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-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.



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 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 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
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 : NSTEPS

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



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
 wrote:
> here is my code for the above problem:
>
> #include
> #include
>
> int main()
> {
>     int i,x[1],y[1],val;
>     long n;
>     scanf("%d",&n);
>     for(i=0;i     {
>         scanf("%d",&x[i]);
>         scanf("%d",&y[i]);
>     }
>     for(i=0;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.



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


#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;


   /*  int size=visited.size();
cout< > &w ,vector &visited,int start_vertex)
 {
  int i,j;
  queue Q;
  Q.push(start_vertex);
  visited[start_vertex] =1;
  while(!Q.empty())
  {
   int i = Q.front();  //
get the tail element from queue
   Q.pop();
   vector::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;
vector >  w(N,vector(0));
  for(i=0;i visit(N,0);

for(i=0;iwrote:

>
> 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
>
> #include#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 
> ("%d",&t);while(t--)
> {
> k++;
> front=-1;
> rear=-1;
> int error=0;
> int visit[MAX]={0};
> visit[0]=1;
> scanf 
> ("%d%d",&num,&action);
> int n=num;
> int arr[num][num],a[num];
> for(i=0;i {
> a[i]=-2;
> for(j=0;j arr[i][j]=0;
> }
> while(action--)
> {
> scanf 
> ("%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;l if(a[l]==-2)
> {
> addq(l);
> n++;
> visit[l]=1;
> break;
> }
> }
> else
> { a[i]=i;
> for(j=i+1;j {
> if(arr[i][j] && i!=j)
> {
> if(visit[j]==visit[i])
> {
> error=1;
> break;
> }
> else if(!visit[j])
> {
> visit[j]=-visit[i];
> addq(j);
> }
> }
> }
> }
> if(error) break;
> }
> printf 
> ("Scenario
>  #%d\n",k);
> if(error)
> printf 
> ("Suspicious
>  bugs found!\n");
> elseprintf 
> ("No 
> suspicious bugs found!\n");
> }return 0;}
>
>
> --
> Dileep Kumar
> 3rd year
> Computer Science & Engineering
> NIT, Allahabad
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@go

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
 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  wrote:
>>
>> what;s your algorithm ?
>>
>> On Mon, Nov 14, 2011 at 7:57 PM, Anshul AGARWAL
>>  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.
>>>
>>>
>>> #include
>>> #include
>>> 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(s>g&&u==0&&d!=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(s>g)
>>>     {
>>>            int temp =s;
>>>            s=g;
>>>            g=temp;
>>>
>>>           // cout<<"2"<>>            }
>>>            //cout<<"1"<>>            c=s;
>>>     if(s>>     {     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)
>>>               {  // cout<<"1"<>>                                p=p+q;
>>>                                c=(q)*u+c;
>>>                                //cout<>>                                }
>>>               else
>>>               {//cout<<"2"<>>                    p=p+temp/u;
>>>                    c=(temp/u)*u+c;
>>>                    }
>>>               if(c==g)
>>>               {
>>>                    //   cout<<"3"<>>                       printf("%lld",p);
>>>                       break;
>>>               }
>>>               if(u==d||d==0||((u%d==0)&&d!=0)||(d%u==0&&u!=0))
>>>               {
>>>
>>>               printf("use the stairs\n");
>>>                             break;}
>>>               if(c-d>=0)
>>>               {      //   cout<<"4"<>>                         c=c-d;
>>>                         p+=1;
>>>                        // cout<>>                         }
>>>                         else
>>>                         {
>>>                          //   cout<<"5"<>>                             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.g

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  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.
>>
>>
>> *
>> #include
>> **
>> #include
>> 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(s>g&&u==0&&d!=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(s>g)
>> {
>>int temp =s;
>>s=g;
>>g=temp;
>>
>>   // cout<<"2"<>}
>>//cout<<"1"<>c=s;
>> if(s> { 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)
>>   {  // cout<<"1"<>p=p+q;
>>c=(q)*u+c;
>>//cout<>}
>>   else
>>   {//cout<<"2"<>p=p+temp/u;
>>c=(temp/u)*u+c;
>>}
>>   if(c==g)
>>   {
>>//   cout<<"3"<>   printf("%lld",p);
>>   break;
>>   }
>>if(u==d||d==0||((u%d==0)&&d!=0)||(d%u==0&&u!=0))
>>   {
>>
>>   printf("use the stairs\n");
>> break;}
>>   if(c-d>=0)
>>   {  //   cout<<"4"<> c=c-d;
>> p+=1;
>>// cout<> }
>> else
>> {
>>  //   cout<<"5"<> 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 shady
what;s your algorithm ?

On Mon, Nov 14, 2011 at 7:57 PM, Anshul AGARWAL
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.
>
>
> *
> #include
> **
> #include
> 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(s>g&&u==0&&d!=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(s>g)
> {
>int temp =s;
>s=g;
>g=temp;
>
>   // cout<<"2"<}
>//cout<<"1" if(s { 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)
>   {  // cout<<"1"c=(q)*u+c;
>//cout<}
>   else
>   {//cout<<"2"c=(temp/u)*u+c;
>}
>   if(c==g)
>   {
>//   cout<<"3"<   printf("%lld",p);
>   break;
>   }
>   if(u==d||d==0||((u%d==0)&&d!=0)||(d%u==0&&u!=0))
>   {
>
>   printf("use the stairs\n");
> break;}
>   if(c-d>=0)
>   {  //   cout<<"4"< c=c-d;
> p+=1;
>// cout< }
> else
> {
>  //   cout<<"5"< 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 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
 






On Tue, Aug 30, 2011 at 10:27 PM, saurabh singh  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,,,
>
> #include
> int main()
> {
> int a[10001],b[10001];
> int i,j;
> int n,m;
> while(scanf("%d",&n)&&n)
> {
> for(i=0;i scanf("%d",&m);
> for(j=0;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;i {
> 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]
> 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(;j for(;i k++;
> l++;
> for(i=0,j=0;i {
> if(c[i]>d[j]) sum+=c[i];
> else sum+=d[j];
> }
> #ifdef DEB
> for(i=0;i printf("%d\t",c[i]);
> puts("");
> for(j=0;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


#include
#include
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.



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



Re: [algogeeks] SPOJ Problem DIVSUM

2011-08-27 Thread Gaurav Menghani
http://lmgtfy.com/?q=pollard%27s+rho+algorithm

On Sat, Aug 27, 2011 at 11:05 PM, Rahul Verma  wrote:
> @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.
>



-- 
Gaurav Menghani

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



Re: [algogeeks] SPOJ Problem DIVSUM

2011-08-27 Thread saurabh modi
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.



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
You might want to check out Pollard Rho algorithm.

On Sat, Aug 27, 2011 at 9:57 PM, Rahul Verma  wrote:
> I am trying to submit solution for the SPOJ DIVSUM problem, but it returns
> the time limit exceeded. Code submitted by me is below:
>
> #include 
> #include 
> using namespace std;
> int proper_divisor(int number);
> int main()
> {
>     int test,i,number;
>     cin>>test;
>     for(i=0; i     {
>         cin>>number;
>         proper_divisor(number);
>     }
> }
> int proper_divisor(int number)
> {
>     int i,n=0;
>     for(i=1; i     {
>         if(number%i==0)
>         {
>            n=n+i;
>         }
>     }
>     //cout< }
>
>
> --
> 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.
>



-- 
Gaurav Menghani

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



Re: [algogeeks] SPOJ 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  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.



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  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 n<0:
> return 0
> if n==0:
> return 1
> i=n
> prod=1
> while i>0 :
> prod*=i
> i-=1
> return prod
> n=input()
> k=input()
> if k==1:
> print n
> elif 2*k>n:
> 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 :
> @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 
> wrote:
>>
>> Matrix exponentiation can help i think
>>
>> On Sun, May 22, 2011 at 10:36 PM, Akshata Sharma
>>  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  wrote:

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

 2011/5/22 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.
 >
 >



 --
 __

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



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 wrote:

>  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  wrote:
>
>> hey me getting wrong ans..can anyone pls help me out
>> here s my code
>> #include
>> #include
>> #include
>> #include
>> 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];
>>   // cout<>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(cin>>s && s[0]!='0')
>>{
>>memset(a,0,sizeof(a));
>>cout<>
>>}
>> }
>>
>>
>> On Wed, Jun 1, 2011 at 3:30 PM, pacific :-) 
>> 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 
>> > #include 
>> > #include 
>> > 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;
>> >   cin>>ch;
>> >   while(ch!='0')
>> > {
>> >   char input[5001];
>> >   int index=0;
>> >   while(ch!='\n')
>> > {
>> >   //input.push_back(ch-'0');
>> >   input[index]=ch;
>> >   index++;
>> >   scanf("%c",&ch);
>> > }
>> >
>> >   cin>>ch;
>> >   head = input ;
>> >   for(int i=0;i<=5000;i++)
>> > result[i]=0;
>> >   cout<> > }
>> > 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
 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  wrote:

> hey me getting wrong ans..can anyone pls help me out
> here s my code
> #include
> #include
> #include
> #include
> 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];
>   // coutans+=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(cin>>s && s[0]!='0')
>{
>memset(a,0,sizeof(a));
>cout<
>}
> }
>
>
> On Wed, Jun 1, 2011 at 3:30 PM, pacific :-)  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 
> > #include 
> > #include 
> > 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;
> >   cin>>ch;
> >   while(ch!='0')
> > {
> >   char input[5001];
> >   int index=0;
> >   while(ch!='\n')
> > {
> >   //input.push_back(ch-'0');
> >   input[index]=ch;
> >   index++;
> >   scanf("%c",&ch);
> > }
> >
> >   cin>>ch;
> >   head = input ;
> >   for(int i=0;i<=5000;i++)
> > result[i]=0;
> >   cout< > }
> > 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 arun kumar
hey me getting wrong ans..can anyone pls help me out
here s my code
#include
#include
#include
#include
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];
   // cout<>s && s[0]!='0')
{
memset(a,0,sizeof(a));
cout< 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 
> #include 
> #include 
> 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;
>   cin>>ch;
>   while(ch!='0')
>     {
>   char input[5001];
>   int index=0;
>   while(ch!='\n')
>     {
>   //input.push_back(ch-'0');
>   input[index]=ch;
>   index++;
>   scanf("%c",&ch);
>     }
>
>   cin>>ch;
>   head = input ;
>   for(int i=0;i<=5000;i++)
>     result[i]=0;
>   cout<     }
> 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 Help

2011-05-30 Thread oldman
Code::Blocks

On Sun, May 29, 2011 at 1:59 AM, Akash Mukherjee  wrote:

> devcpp
>
>
> On Sat, May 28, 2011 at 11:17 PM, sravanreddy001  > 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.



Re: [algogeeks] SPOJ Problem Help

2011-05-28 Thread Akash Mukherjee
devcpp

On Sat, May 28, 2011 at 11:17 PM, sravanreddy001
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.



Re: [algogeeks] SPOJ Problem Help

2011-05-28 Thread Aakash Johari
Install Cygwin
and Vim Editor for Windows
This is what I use.

On Sat, May 28, 2011 at 10:47 AM, sravanreddy001
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.
>



-- 
-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 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-28 Thread Akshata Sharma
thanks all :)

On Sat, May 28, 2011 at 8:08 PM, sukhmeet singh wrote:

> 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 wrote:
>
>> @sukhmeetyour code is having runtime error !!
>>
>>
>> On Sat, May 28, 2011 at 4:48 AM, sukhmeet singh 
>> wrote:
>>
>>> 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 wrote:
>>>
 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*/
> #include
>
>
>
>
>
> #include
>
>
>
>
>
>
> 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(lo
>
>
>
>
>
>  {
>   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 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 wrote:

> @sukhmeetyour code is having runtime error !!
>
>
> On Sat, May 28, 2011 at 4:48 AM, sukhmeet singh wrote:
>
>> 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 wrote:
>>
>>> 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*/
 #include




 #include





 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(lo>>>




  {
   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 Logic King
@sukhmeetyour code is having runtime error !!

On Sat, May 28, 2011 at 4:48 AM, sukhmeet singh wrote:

> 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 wrote:
>
>> 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*/
>>> #include
>>>
>>>
>>>
>>> #include
>>>
>>>
>>>
>>>
>>> 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(lo>>
>>>
>>>
>>>
>>>  {
>>>   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
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 wrote:

> Precompute the values. and then do queries.
>
>
> On Sat, May 28, 2011 at 1:46 AM, Akshata Sharma  > wrote:
>
>> My code gives TLE. What further optimization is required in my code??
>> https://www.spoj.pl/problems/FACVSPOW/
>>
>>
>> /*FACVSPOW*/
>> #include
>>
>> #include
>>
>>
>> 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(lo>
>>
>>  {
>>   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 Aakash Johari
Precompute the values. and then do queries.

On Sat, May 28, 2011 at 1:46 AM, Akshata Sharma
wrote:

> My code gives TLE. What further optimization is required in my code??
> https://www.spoj.pl/problems/FACVSPOW/
>
>
> /*FACVSPOW*/
> #include
> #include
>
> 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(lo
>  {
>   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-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 wrote:

> @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  > 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 
>> wrote:
>>
>>> @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 (n&1) 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.



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
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 
> wrote:
>
>> @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 (n&1) 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 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 wrote:

> @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 (n&1) 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 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 (n&1) 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 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 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 a>b..
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 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 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  wrote:
>>
>>> Try thinking backwards.
>>> (0,1),(1,2),(2,3),(3,5),(5,8),(8,13),...
>>>
>>> 2011/5/22 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.
>>> >
>>> >
>>>
>>>
>>>
>>> --
>>> __
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from 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-22 Thread Aakash Johari
Matrix exponentiation can help i think

On Sun, May 22, 2011 at 10:36 PM, Akshata Sharma
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  wrote:
>
>> Try thinking backwards.
>> (0,1),(1,2),(2,3),(3,5),(5,8),(8,13),...
>>
>> 2011/5/22 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.
>> >
>> >
>>
>>
>>
>> --
>> __
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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-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  wrote:

> Try thinking backwards.
> (0,1),(1,2),(2,3),(3,5),(5,8),(8,13),...
>
> 2011/5/22 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.
> >
> >
>
>
>
> --
> __
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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 tec
Try thinking backwards.
(0,1),(1,2),(2,3),(3,5),(5,8),(8,13),...

2011/5/22 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.
>
>



-- 
__

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

> 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:
>>
>> #include
>> #include
>> #include
>> #include
>> #include
>> using namespace std;
>> class pi
>> {
>>public:
>>int a,b;
>>pi(){a=0;b=0;}
>>pi(int x,int y) {a=x;b=y;}
>> };
>> vector 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;
>>}
>> //  cout<>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));
>>//  cout<>vector temp(size);
>>tree=temp;
>>temp.clear();
>>string s;
>>cin>>s;
>>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 algo

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:
>
> #include
> #include
> #include
> #include
> #include
> using namespace std;
> class pi
> {
>public:
>int a,b;
>pi(){a=0;b=0;}
>pi(int x,int y) {a=x;b=y;}
> };
> vector 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;
>}
> //  coutbuild(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));
>//  couttree=temp;
>temp.clear();
>string s;
>cin>>s;
>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

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


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

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.



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  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-BRCKTS

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

On Mon, Mar 21, 2011 at 9:19 AM, Anurag atri wrote:

> @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 
>> wrote:
>>
>>> @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 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 "NO"and i was printing "NO" as
>> "No"It 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.



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 wrote:
>
>> @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 >> > 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 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 "NO"and i was printing "NO" as
> "No"It 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
@bharath yaa now I got the ques, thanx :-)

On Mon, Mar 21, 2011 at 4:47 AM, bharath kannan wrote:

> @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 
>> 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 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 "NO"and i was printing "NO" as
 "No"It 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 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 
> 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  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 "NO"and i was printing "NO" as "No"It
>>> 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
@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 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  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 "NO"and i was printing "NO" as "No"It
>> 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-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  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 "NO"and i was printing "NO" as "No"It
> 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.



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  wrote:

> Here is my code for TRICOUNT problem
>
> //http://www.spoj.pl/problems/TRICOUNT/
> //cegprak...@gmail.com
>
> #include
> #include
> 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;i<1;i++){
>arr[i]=i+1+arr[i-1];
>}
>for(i=0;i<1;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;
> }
>}
>cin>>t;
>while(t--){
> cin>>n;
> cout<}
>
>
>
>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-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 "NO"and i was printing "NO" as "No"It
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 : 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  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;i{
>scanf("\n%d %d",&a[i],&b[i]);
>}
>for(i=0;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-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:
>
> #include
> #include
> #include
> #include
> #include
> using namespace std;
> class pi
> {
>public:
>int a,b;
>pi(){a=0;b=0;}
>pi(int x,int y) {a=x;b=y;}
> };
> vector 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;
>}
> //  coutbuild(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));
>//  couttree=temp;
>temp.clear();
>string s;
>cin>>s;
>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

2011-03-15 Thread Algoose chase
Can you explain your code ?

On Thu, Mar 10, 2011 at 10:22 AM, UTKARSH SRIVASTAV  wrote:

> WELL I HAVE DONE THIS PROBLEM .HERE IS THE CODE
> #include
> #include
> using namespace std;
> main()
> {
> long long int t[2][2010],price[2010],r,c,i,j,n;
> scanf("%lld",&n);
> for(i=0;i {
> scanf("%lld",&price[i]);
> }
> for(r=n-1,c=0;r>=0&&c<=n-1;r--,c++)
> {
> for(i=r,j=n-1;i>=0&&j>=c;j--,i--)
>
> t[i&1][j]=max(price[i]*(n+i-j)+t[(i+1)&1][j],price[j]*(n+i-j)+t[i&1][j-1]);
> }
> printf("%lld\n",t[0][n-1]);
> return 0;
> }
>
>
>
> On Wed, Mar 9, 2011 at 5:10 PM, Algoose chase wrote:
>
>> Hi,
>>
>> Any solution other than brute force(exponential growth) for this problem ?
>>
>>
>> On Sun, Mar 6, 2011 at 6:42 PM, UTKARSH SRIVASTAV <
>> usrivastav...@gmail.com> wrote:
>>
>>> can anyone please tell me why i am getting wrong answer for
>>> problem.https://www.spoj.pl/problems/TRT/
>>> .
>>> .
>>> .
>>> MY CODE IS THIS AND TO BE TESTED IN gcc COMPILER
>>>
>>>
>>> #include
>>> double a[2100];
>>> double fun(long long int  m,long long int n,double count)
>>> {
>>>double k,l;
>>>count++;
>>>if(m==n)
>>>{
>>>
>>>return count*a[m];
>>>}
>>>if((k=(fun(m+1,n,count)))>(l=(fun(m,n-1,count
>>>{
>>>
>>>return (count*a[m]+k);
>>>}
>>>else
>>>{
>>>
>>>
>>>return (count*a[n]+l);
>>>}
>>> }
>>> int main()
>>> {
>>>long long int i,m,n;
>>>double ans,c=0;
>>>scanf("%lld",&n);
>>>for(i=1;i<=n;i++)
>>>{
>>>scanf("%lf",&a[i]);
>>>}
>>>m=1;
>>>ans=fun(m,n,c);
>>>printf("%.0lf\n",ans);
>>>return 0;
>>> }
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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 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
#include
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/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
wrote:

> 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

 #include
 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;i>>> {
 scanf("%lld",&r);
 if(r!=major)
 {
 count--;
 if(count<0)
 {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.



Re: [algogeeks] Spoj Problem

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

Thanks,
Balaji.

On Tue, Mar 15, 2011 at 11:00 PM, Akshata Sharma
wrote:

> hey link to the problem??
>
>
> On Tue, Mar 15, 2011 at 10:50 PM, Balaji Ramani  > 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
>>>
>>> #include
>>> 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;i>> {
>>> scanf("%lld",&r);
>>> if(r!=major)
>>> {
>>> count--;
>>> if(count<0)
>>> {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 Akshata Sharma
hey link to the problem??

On Tue, Mar 15, 2011 at 10:50 PM, Balaji Ramani
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
>>
>> #include
>> 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;i> {
>> scanf("%lld",&r);
>> if(r!=major)
>> {
>> count--;
>> if(count<0)
>> {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
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
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
>
> #include
> 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;i {
> scanf("%lld",&r);
> if(r!=major)
> {
> count--;
> if(count<0)
> {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 Ankur Khurana
@utraksh : 10^9 is well in int limits

On Tue, Mar 15, 2011 at 12:56 PM, Satyam Kapoor wrote:

> @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 Satyam Kapoor
@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.



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  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 wrote:
>
>> Here is my solution.i got it AC
>>
>> #include
>> 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(n>0)
>>scanf("%d",&arr[0]);
>>for(i=1;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;i>{
>>ans+=((ard[i]/min)-1);
>>}
>>printf("%d",ans);
>> return 0;
>>
>> }
>>
>>
>>
>> On Sat, Mar 12, 2011 at 7:37 PM, Balaji Ramani > > wrote:
>>
>>> Yeah, I too am wondering how to implement more efficiently.
>>>
>>>
>>> On Sat, Mar 12, 2011 at 7:36 PM, Satyam Kapoor >> > 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-14 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 wrote:

> Here is my solution.i got it AC
>
> #include
> 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(n>0)
>scanf("%d",&arr[0]);
>for(i=1;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;i{
>ans+=((ard[i]/min)-1);
>}
>printf("%d",ans);
> return 0;
>
> }
>
>
>
> On Sat, Mar 12, 2011 at 7:37 PM, Balaji Ramani 
> wrote:
>
>> Yeah, I too am wondering how to implement more efficiently.
>>
>>
>> On Sat, Mar 12, 2011 at 7:36 PM, Satyam Kapoor 
>> 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.



Re: [algogeeks] Spoj Problem : String based

2011-03-13 Thread Logic King
U didn't understand my problem.i have the problem with this line --

"The length of the needle is only limited by the memory available to your
program, so do not make any assumptions - instead, read the length and
allocate memory as needed."

On Sun, Mar 13, 2011 at 4:00 PM, sukhmeet singh wrote:

> in order to deal with such situations u have to read the input till the end
> of file
> if your algo is correct then using EOF something like
> while(scanf("%d",&n)!=EOF) will give u AC..!!
>
> On Sun, Mar 13, 2011 at 2:01 PM, Logic King wrote:
>
>>  I tried the problem https://www.spoj.pl/problems/NHAY/
>>
>> I didn't Understand the Input of the problem --
>> The length of the needle is only limited by the memory available to your
>> program, so do not make any assumptions - instead, read the length and
>> allocate memory as needed. The haystack is *not* limited in size, which
>> implies that your program should not read the whole haystack at once. The
>> KMP algorithm is stream-based, i.e. it processes the haystack character by
>> character, so this is not a problem.
>>
>> my code works fine i the size of both the strings are limited
>>
>> i created my own algo...didn't did it by KMP.plz help me how to
>> control the large input !!
>>
>>
>> my code is--
>>
>> #include
>> #include
>>
>> int main()
>> {
>> int t,i,j,n,l1,l2;
>> char p[1000],str[1000];
>> scanf("%d",&t);
>> while(t--)
>> {
>> scanf("%d",&n);
>> i=0;
>> scanf("%s",p);
>> scanf("%s",str);
>> l1=strlen(str);l2=strlen(p);
>> for(j=0;j> {
>>
>> if(i> {
>> if(str[i]==p[j])
>> {
>> if(j==l2-1)
>> {
>> printf("%d\n",i-l2+1);
>> j=0;
>> i=i-l2+2;
>> }
>> else
>> {
>> i++;
>> j++;
>> }
>> }
>> else
>> {
>> if(j==0)
>> i++;
>> else
>> j=0;
>> }
>> }
>> else
>> break;
>> }
>> printf("\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.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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 : String based

2011-03-13 Thread sukhmeet singh
in order to deal with such situations u have to read the input till the end
of file
if your algo is correct then using EOF something like
while(scanf("%d",&n)!=EOF) will give u AC..!!

On Sun, Mar 13, 2011 at 2:01 PM, Logic King wrote:

> I tried the problem https://www.spoj.pl/problems/NHAY/
>
> I didn't Understand the Input of the problem --
> The length of the needle is only limited by the memory available to your
> program, so do not make any assumptions - instead, read the length and
> allocate memory as needed. The haystack is *not* limited in size, which
> implies that your program should not read the whole haystack at once. The
> KMP algorithm is stream-based, i.e. it processes the haystack character by
> character, so this is not a problem.
>
> my code works fine i the size of both the strings are limited
>
> i created my own algo...didn't did it by KMP.plz help me how to control
> the large input !!
>
>
> my code is--
>
> #include
> #include
>
> int main()
> {
> int t,i,j,n,l1,l2;
> char p[1000],str[1000];
> scanf("%d",&t);
> while(t--)
> {
> scanf("%d",&n);
> i=0;
> scanf("%s",p);
> scanf("%s",str);
> l1=strlen(str);l2=strlen(p);
> for(j=0;j {
>
> if(i {
> if(str[i]==p[j])
> {
> if(j==l2-1)
> {
> printf("%d\n",i-l2+1);
> j=0;
> i=i-l2+2;
> }
> else
> {
> i++;
> j++;
> }
> }
> else
> {
> if(j==0)
> i++;
> else
> j=0;
> }
> }
> else
> break;
> }
> printf("\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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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-12 Thread Akshata Sharma
https://www.spoj.pl/problems/STREETR/

On 3/12/11, kumar anurag  wrote:
> which probem ? pls gve the link
> On Sat, Mar 12, 2011 at 8:27 PM, Akshata Sharma
> wrote:
>
>> yeah I too got AC. The way I was calculating gcd was not efficient. :)
>>
>> On 3/12/11, Logic King  wrote:
>> > Here is my solution.i got it AC
>> >
>> > #include
>> > 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(n>0)
>> >scanf("%d",&arr[0]);
>> >for(i=1;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;i> >{
>> >ans+=((ard[i]/min)-1);
>> >}
>> >printf("%d",ans);
>> > return 0;
>> > }
>> >
>> >
>> >
>> > On Sat, Mar 12, 2011 at 7:37 PM, Balaji Ramani
>> > wrote:
>> >
>> >> Yeah, I too am wondering how to implement more efficiently.
>> >>
>> >>
>> >> On Sat, Mar 12, 2011 at 7:36 PM, Satyam Kapoor
>> >> 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.
>> >
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> Kumar Anurag
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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-12 Thread kumar anurag
which probem ? pls gve the link
On Sat, Mar 12, 2011 at 8:27 PM, Akshata Sharma
wrote:

> yeah I too got AC. The way I was calculating gcd was not efficient. :)
>
> On 3/12/11, Logic King  wrote:
> > Here is my solution.i got it AC
> >
> > #include
> > 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(n>0)
> >scanf("%d",&arr[0]);
> >for(i=1;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;i >{
> >ans+=((ard[i]/min)-1);
> >}
> >printf("%d",ans);
> > return 0;
> > }
> >
> >
> >
> > On Sat, Mar 12, 2011 at 7:37 PM, Balaji Ramani
> > wrote:
> >
> >> Yeah, I too am wondering how to implement more efficiently.
> >>
> >>
> >> On Sat, Mar 12, 2011 at 7:36 PM, Satyam Kapoor
> >> 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.
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Kumar Anurag

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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-12 Thread Akshata Sharma
yeah I too got AC. The way I was calculating gcd was not efficient. :)

On 3/12/11, Logic King  wrote:
> Here is my solution.i got it AC
>
> #include
> 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(n>0)
>scanf("%d",&arr[0]);
>for(i=1;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;i{
>ans+=((ard[i]/min)-1);
>}
>printf("%d",ans);
> return 0;
> }
>
>
>
> On Sat, Mar 12, 2011 at 7:37 PM, Balaji Ramani
> wrote:
>
>> Yeah, I too am wondering how to implement more efficiently.
>>
>>
>> On Sat, Mar 12, 2011 at 7:36 PM, Satyam Kapoor
>> 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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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-12 Thread Logic King
Here is my solution.i got it AC

#include
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(n>0)
   scanf("%d",&arr[0]);
   for(i=1;iwrote:

> Yeah, I too am wondering how to implement more efficiently.
>
>
> On Sat, Mar 12, 2011 at 7:36 PM, Satyam Kapoor 
> 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.



Re: [algogeeks] spoj problem

2011-03-12 Thread Balaji Ramani
Yeah, I too am wondering how to implement more efficiently.

On Sat, Mar 12, 2011 at 7:36 PM, Satyam Kapoor 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.



Re: [algogeeks] spoj problem

2011-03-12 Thread Satyam Kapoor
@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.



Re: [algogeeks] spoj problem

2011-03-12 Thread Balaji Ramani
@Akshata, Satyam: I think that might be because the way you are using to
calculate gcd is inefficient.

I got AC.

I used the following technique to calculate gcd:

long long int gcd(long long int a, long long int b){
  long long int rem = a%b;
  if(rem == 0) return b;
  return gcd(b,rem);
}

long long int gcdvar = a[1]-a[0];
for(i=2;iwrote:

>
> @Balaji:
> that WA was due to using int in place of long long in loop. But still, this
> is giving TLE.
>
> On Sat, Mar 12, 2011 at 7:07 PM, Akshata Sharma  > wrote:
>
>> sorry, @satyam: then what is the 'best' solution for this? :)
>>
>>
>> On Sat, Mar 12, 2011 at 7:06 PM, Akshata Sharma <
>> akshatasharm...@gmail.com> wrote:
>>
>>> @Ankur: then what is the 'best' solution for this? :)
>>> @Balaji: i tried implementing but I dont know which case it fails??
>>> getting WA now!!
>>> Here is the code:
>>>
>>> #include
>>>
>>> int main()
>>> {
>>>  long n,gcd=1;
>>>  scanf("%d",&n);
>>>  long long a[n],b[n],cnt=0,sum=0;
>>>  long long min=9;
>>>  scanf("%lld",&a[0]);
>>>
>>>  for(long i=1;i>>   {
>>>  scanf("%lld",&a[i]);
>>>  b[i-1]=a[i]-a[0];
>>>  if(min>b[i-1])
>>>  min=b[i-1];
>>>   }
>>>
>>>
>>> for(int k=min;k>0;k--)
>>> {
>>> cnt=0;
>>> for(int i=0;i>> {
>>> if(b[i]%k==0)
>>> cnt++;
>>> }
>>>
>>> if(cnt==n-1)
>>> {
>>> gcd=k;
>>> break;
>>> }
>>> }
>>>
>>> sum=((a[n-1]-a[0])/gcd)-n+1;
>>> printf("%lld\n",sum);
>>> return 0;
>>>
>>> }
>>>
>>> On Sat, Mar 12, 2011 at 2:38 PM, Satyam Kapoor >> > wrote:
>>>

 this is gud but not the best soln.

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



Re: [algogeeks] spoj problem

2011-03-12 Thread Akshata Sharma
@Balaji:
that WA was due to using int in place of long long in loop. But still, this
is giving TLE.
On Sat, Mar 12, 2011 at 7:07 PM, Akshata Sharma
wrote:

> sorry, @satyam: then what is the 'best' solution for this? :)
>
>
> On Sat, Mar 12, 2011 at 7:06 PM, Akshata Sharma  > wrote:
>
>> @Ankur: then what is the 'best' solution for this? :)
>> @Balaji: i tried implementing but I dont know which case it fails??
>> getting WA now!!
>> Here is the code:
>>
>> #include
>>
>> int main()
>> {
>>  long n,gcd=1;
>>  scanf("%d",&n);
>>  long long a[n],b[n],cnt=0,sum=0;
>>  long long min=9;
>>  scanf("%lld",&a[0]);
>>
>>  for(long i=1;i>   {
>>  scanf("%lld",&a[i]);
>>  b[i-1]=a[i]-a[0];
>>  if(min>b[i-1])
>>  min=b[i-1];
>>   }
>>
>>
>> for(int k=min;k>0;k--)
>> {
>> cnt=0;
>> for(int i=0;i> {
>> if(b[i]%k==0)
>> cnt++;
>> }
>>
>> if(cnt==n-1)
>> {
>> gcd=k;
>> break;
>> }
>> }
>>
>> sum=((a[n-1]-a[0])/gcd)-n+1;
>> printf("%lld\n",sum);
>> return 0;
>>
>> }
>>
>> On Sat, Mar 12, 2011 at 2:38 PM, Satyam Kapoor 
>> wrote:
>>
>>>
>>> this is gud but not the best soln.
>>>
>>> --
>>> 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.



Re: [algogeeks] spoj problem

2011-03-12 Thread Satyam Kapoor
@akshata:i did this one by hcf method but it took too much time...

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



Re: [algogeeks] spoj problem

2011-03-12 Thread Akshata Sharma
sorry, @satyam: then what is the 'best' solution for this? :)

On Sat, Mar 12, 2011 at 7:06 PM, Akshata Sharma
wrote:

> @Ankur: then what is the 'best' solution for this? :)
> @Balaji: i tried implementing but I dont know which case it fails?? getting
> WA now!!
> Here is the code:
>
> #include
>
> int main()
> {
>  long n,gcd=1;
>  scanf("%d",&n);
>  long long a[n],b[n],cnt=0,sum=0;
>  long long min=9;
>  scanf("%lld",&a[0]);
>
>  for(long i=1;i   {
>  scanf("%lld",&a[i]);
>  b[i-1]=a[i]-a[0];
>  if(min>b[i-1])
>  min=b[i-1];
>   }
>
>
> for(int k=min;k>0;k--)
> {
> cnt=0;
> for(int i=0;i {
> if(b[i]%k==0)
> cnt++;
> }
>
> if(cnt==n-1)
> {
> gcd=k;
> break;
> }
> }
>
> sum=((a[n-1]-a[0])/gcd)-n+1;
> printf("%lld\n",sum);
> return 0;
>
> }
>
> On Sat, Mar 12, 2011 at 2:38 PM, Satyam Kapoor 
> wrote:
>
>>
>> this is gud but not the best soln.
>>
>> --
>> 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.



Re: [algogeeks] spoj problem

2011-03-12 Thread Akshata Sharma
@Ankur: then what is the 'best' solution for this? :)
@Balaji: i tried implementing but I dont know which case it fails?? getting
WA now!!
Here is the code:

#include

int main()
{
 long n,gcd=1;
 scanf("%d",&n);
 long long a[n],b[n],cnt=0,sum=0;
 long long min=9;
 scanf("%lld",&a[0]);

 for(long i=1;ib[i-1])
 min=b[i-1];
  }


for(int k=min;k>0;k--)
{
cnt=0;
for(int i=0;iwrote:

>
> this is gud but not the best soln.
>
> --
> 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.



  1   2   >