Search found 383 matches

by emotional blind
Sun May 18, 2008 10:39 am
Forum: Volume 105 (10500-10599)
Topic: 10533 - Digit Primes
Replies: 108
Views: 31625

Re: 10533 - Digit Primes

probably your is_dp function is costly. try to re-implement this is_dp using something real dp :P Something like this - int ds[SIZE]; int dsum(int n){ int &ret = ds[n]; if(-1!=ret)return ret; if(n<10)return ret=n; return ret = n%10 + dsum(n/10); } void is_dp(){ long x,z,ct=0,du,m=0; memset(ds,-1,siz...
by emotional blind
Tue Apr 01, 2008 8:21 pm
Forum: Volume 4 (400-499)
Topic: 438 - The Circumference of the Circle
Replies: 29
Views: 9387

Re:

RC's wrote: Is it because of precision error ?
Not sure, but It could be. What is your value of pi? I defined it as 3.141592653589793
by emotional blind
Mon Mar 31, 2008 5:09 am
Forum: Volume 114 (11400-11499)
Topic: 11444 - Sum
Replies: 8
Views: 1668

k<=20
by emotional blind
Wed Mar 26, 2008 5:43 am
Forum: Volume 9 (900-999)
Topic: 902 - Password Search
Replies: 68
Views: 31890

kenneth wrote:
emotional blind wrote:hint: I solved it using O(n*k) algorithm.
Care to share your method?
try to implement a TRIE.
by emotional blind
Fri Mar 21, 2008 2:22 pm
Forum: Volume 9 (900-999)
Topic: 902 - Password Search
Replies: 68
Views: 31890

hint: I solved it using O(n*k) algorithm.
by emotional blind
Thu Mar 20, 2008 9:34 pm
Forum: Volume 114 (11400-11499)
Topic: 11424 - GCD - Extreme (I)
Replies: 25
Views: 6785

your euler phi generation is too much costly, try something like sieve.
by emotional blind
Thu Mar 20, 2008 7:19 pm
Forum: Volume 102 (10200-10299)
Topic: 10252 - Common Permutation
Replies: 150
Views: 51296

when length of a = 1000, and strlen(a) = 1000 then you can't access a[strlen(a)] ie a[1000], coz your size of array is 1000 so that you can access 0 to 999. try increasing size by 1 ie set the max size to 1001.
by emotional blind
Thu Mar 20, 2008 7:05 pm
Forum: Volume 103 (10300-10399)
Topic: 10364 - Square
Replies: 47
Views: 14837

your code fails for this input

Code: Select all

1
8
1 1 1 1 1 1 1 1
by emotional blind
Thu Mar 20, 2008 6:42 pm
Forum: Volume 9 (900-999)
Topic: 902 - Password Search
Replies: 68
Views: 31890

kenneth wrote:The complexity of the algorithm is O(n) as you only need to go thru the string once followed by going thru the map once. Hope this helps.
but access map and insertion in map will cost O(logn), Sor your algorithm is not O(n) it is O(nlogn).
by emotional blind
Thu Mar 20, 2008 10:53 am
Forum: Volume 108 (10800-10899)
Topic: 10880 - Colin and Ryan
Replies: 45
Views: 28010

What about this input

Code: Select all

1
100 50
by emotional blind
Wed Mar 19, 2008 2:22 pm
Forum: Volume 114 (11400-11499)
Topic: 11420 - Chest of Drawers
Replies: 11
Views: 4989

:D i finally got ac but i think the recursive function of the DP is n(a,b,1)=n(a-1,b-1,1)+n(a-1,b-1,0) n(a,b,0)=n(a-1,b+1,1)+n(a-1,b,0) a is the number of drawer and b is the secured-num and the 0 or 1 means that the situation of the top drawer. Finally thank all of you^^ n(a,b,0)=n(a-1,b+1,1)+n(a-...
by emotional blind
Wed Mar 19, 2008 2:08 pm
Forum: Volume 108 (10800-10899)
Topic: 10880 - Colin and Ryan
Replies: 45
Views: 28010

Re: WA...

Obaida wrote:But I got Wa.. again and again... I send you the code in private msg..
Most probably you did a common mistake.
you checked m>b but you didn't check whether n/m >b or not.
by emotional blind
Wed Mar 19, 2008 10:06 am
Forum: Volume 108 (10800-10899)
Topic: 10880 - Colin and Ryan
Replies: 45
Views: 28010

Obaida, To generate all divisors of n, there is a better way than O(n) solution. For every divisors m less than sqrt(n) there n/m will also be a divisor of n, which will be greater than n. for example if you findout all divisors of 24. you need to try only upto floor( sqrt(24) ) = 4. 1. 1 is a divis...
by emotional blind
Wed Mar 19, 2008 9:34 am
Forum: Volume 114 (11400-11499)
Topic: 11420 - Chest of Drawers
Replies: 11
Views: 4989

Code: Select all

nway(n, s, pdl)  = nway(n-1, s, 0) + nway(n-1, s-1, 1)    if pdl=1
                        = nway(n-1, s, 0) + nway(n-1, s, 1) if pdl =0
here,
n = number of drawer
s = number of drawer to be secured
pdl = last drawer locked or not [1 means locked]
by emotional blind
Sun Mar 16, 2008 7:05 pm
Forum: Volume 114 (11400-11499)
Topic: 11424 - GCD - Extreme (I)
Replies: 25
Views: 6785

T(n)=N*(1-1/p1)(1-1/p2)... reorganize this equation if n = p1^k1 * p2^k * ... then T(n) = ( p1^k - P1^(k-1) ) * ( p2^k - P2^(k-1) ) * ... from this equation it is easy to realize how sieve will do. initialize table with 1. and for every prime factor of n., T[n] will be hit once, and multiply it by p...

Go to advanced search