Re: [algogeeks] Re: problem

2012-06-10 Thread Piyush Kapoor
A correction, it is *(2^p) - 1 *, and the answer (*2^(number of primes less than n)) - 1* .(It is simply taking any subset of the primes,leaving the one in which do not take any prime) On Sun, Jun 10, 2012 at 10:03 PM, Piyush Kapoor wrote: > The problem simply asks you to calculate the number of

Re: [algogeeks] Re: problem

2012-06-10 Thread Piyush Kapoor
The problem simply asks you to calculate the number of ways to express a number( = *N!^N!*) as product of two co prime numbers. For a general *N* , it is simply equal to *2^(p-1)* , where *p * is the number of distinct prime factors of *N*. For *N!* , *p* will be number of primes less than *N* , a

Re: [algogeeks] Re: problem

2012-06-10 Thread payel roy
Can you please simplify the algorithm? Solution is not clear from the posted submissions !!! On 10 June 2012 20:32, KK wrote: > This problem is of ACM-ICPC kanpur online round 2012. > you can find the solution > here > . > > > On Sunday, 10 Ju

[algogeeks] Re: problem

2012-06-10 Thread KK
This problem is of ACM-ICPC kanpur online round 2012. you can find the solution here . On Sunday, 10 June 2012 16:37:33 UTC+5:30, payel roy wrote: > > Find the number of fractions a/b such that- > > 1. *gcd(a, b) = 1* > 2. *0 < a/b < 1* > 3.

Re: [algogeeks] Re: problem

2012-06-10 Thread payel roy
No constraints as such! On 10 June 2012 17:19, Nachammai Lakshmanan wrote: > what are the constraints or limits for a,b and n?? > > On Jun 10, 3:07 pm, payel roy wrote: > > Find the number of fractions a/b such that- > > > > 1. *gcd(a, b) = 1* > > 2. *0 < a/b < 1* > > 3. *a * b = (n!) ^ (n!)* >

[algogeeks] Re: problem

2012-06-10 Thread Nachammai Lakshmanan
what are the constraints or limits for a,b and n?? On Jun 10, 3:07 pm, payel roy wrote: > Find the number of fractions a/b such that- > > 1. *gcd(a, b) = 1* > 2. *0 < a/b < 1* > 3. *a * b = (n!) ^ (n!)* > > Where *"n!"* denotes the factorial of n and "^" denotes power, *i.e. (2!) ^ > (2!) = 4*.

RE: [algogeeks] Re: problem with increment operator

2012-05-30 Thread Ashot Madatyan
expressions where the same object is modified within the sub-expressions. Regards, Ashot Madatyan From: algogeeks@googlegroups.com [mailto:algogeeks@googlegroups.com] On Behalf Of holmes Sent: Wednesday, May 30, 2012 3:21 PM To: algogeeks@googlegroups.com Subject: [algogeeks] Re: problem

[algogeeks] Re: problem with increment operator

2012-05-30 Thread holmes
It's output will be compiler dependent. So on Turbo C, compiler will perform all pre-increment operation first then will start adding. like in your problem all "++a" operation will go first. then addition will happen. so 6+6+6=18. on gcc, first two variables will it take, performs pre-increment

[algogeeks] Re: Problem

2011-11-19 Thread Zyro
@all : Thanks :) On Nov 19, 3:55 pm, Amol Sharma wrote: > that's what i was saying :) > -- > > Amol Sharma > Third Year Student > Computer Science and Engineering > MNNIT Allahabad >   >

Re: [algogeeks] Re: Problem

2011-11-19 Thread Amol Sharma
that's what i was saying :) -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad On Sat, Nov 19, 2011 at 2:10 PM

[algogeeks] Re: Problem

2011-11-19 Thread shady
sorry, we don't need to do so much computation minimizing the difference of the maximum and minimum array in the selected array is the solution. difference will always be = largest element - smallest element On Nov 19, 1:20 pm, shady wrote: > aim : minimize the sum of elements of a sorted set of

[algogeeks] Re: Problem

2011-11-19 Thread shady
@amol how ? we are not minimizing the difference between the greatest and smallest element in the set, but the difference of the sum of the consecutive elements in the sorted selected array of size k... and complexity O(logn) ? On Nov 19, 1:25 pm, Amol Sharma wrote: > agree with mehdi's solution.

Re: [algogeeks] Re: Problem

2011-11-19 Thread Amol Sharma
agree with mehdi's solution.minimizing sum of differences will be equivalent to minimizing the difference between the largest and smallest number in the setO(logn) solution.. -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad

[algogeeks] Re: Problem

2011-11-19 Thread shady
aim : minimize the sum of elements of a sorted set of size k. mehdi's solution is correct, 1. sort the whole array, 2. and then as you add new element to the set a. delete the oldest element added along with its difference b. add the difference of the newly added element. O(nlogn) On Nov 19

[algogeeks] Re: Problem

2011-11-18 Thread Zyro
The Sum of the difference in the Subset containing the K elements must be minimum... As in above example {9,5,2,6,3,11} where K=3 In case of {2,3,5} 3-2=1 5-3=2 sum of the difference is 3...In all other subsets we cant have sum of the difference less than 3...so {2,3,5} is the required answer.

[algogeeks] Re: Problem

2011-11-18 Thread Zyro
@Shady : Ya ..U can call it to minimize the sum in the subset. On Nov 19, 10:03 am, shady wrote: > what do you mean by difference among them ? > do we need to select the elements to minimize the sum between > consecutive elements ? or only the first and last element ? > > On Nov 18, 6:30 pm, Zyro

[algogeeks] Re: Problem

2011-11-18 Thread Zyro
sorry...minimize sum of the difference between the elements of the subset.. On Nov 19, 10:03 am, shady wrote: > what do you mean by difference among them ? > do we need to select the elements to minimize the sum between > consecutive elements ? or only the first and last element ? > > On Nov 18,

[algogeeks] Re: Problem

2011-11-18 Thread shady
what do you mean by difference among them ? do we need to select the elements to minimize the sum between consecutive elements ? or only the first and last element ? On Nov 18, 6:30 pm, Zyro wrote: > Q: Select the K elements in an array of size N which are having the > minimum difference among t

Re: [algogeeks] Re: Problem of calculating large binomial coefficients which large base so lucas theorem cant be applied

2011-11-06 Thread pankajsingh
Thanks Dave, but i want some more efficient in my case, something like O(k) to calculate all mC1 mC2...mCk, i already had a worst time O(k^2), i.e for (long long int i1=1;i1<=k;i1++) { while((result*(m-i1+1))%i1) { result=result+17; } result=(result*( m-i1+1)); result /= i1; result=result

[algogeeks] Re: Problem of calculating large binomial coefficients which large base so lucas theorem cant be applied

2011-11-06 Thread Dave
@Pankajsingh: See the recent thread "Modular arithmetic + Combinatorics" in this newsgroup. Dave On Nov 6, 12:49 am, pankajsingh wrote: > i want to calculate values like (100 C 1) %17,what would be > better algorithm for it,i think lucas theorem cant be used in this > case.want s

[algogeeks] Re: Problem

2011-11-01 Thread SAMMM
Topology Sort :- Just want to share something to u all . The field's where Topology sort is used :- • Email loops. • Compilation units. • Class inheritance. • Course prerequisites. • Deadlocking detection. • Precedence scheduling. • Temporal dependencies. • Pipeline of computing jobs. • Check f

[algogeeks] Re: Problem on overflow

2011-08-30 Thread Ankuj Gupta
If both number are negative shouldn't be b < min_int - a On Aug 28, 11:49 pm, "Avinash LetsUncomplicate.." wrote: > @Saurabh being ready to run your code for unsatisfactory input doesn't > seem more logical than trying to find out if you can do something > about it. i would have loved a kind repl

Re: [algogeeks] Re: Problem on overflow

2011-08-28 Thread Avinash LetsUncomplicate..
@Saurabh being ready to run your code for unsatisfactory input doesn't seem more logical than trying to find out if you can do something about it. i would have loved a kind reply from you. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To po

Re: [algogeeks] Re: Problem on overflow

2011-08-28 Thread mohit verma
if( unsigned int (a) + unsigned int (b) < 0) return "overflow" else return "ok"; On Sun, Aug 28, 2011 at 7:23 PM, saurabh singh wrote: > @avinash in that case the number will become negative,It wont remain a > satisfactory input.Try to think logically and believe me once you get the > logic

Re: [algogeeks] Re: Problem on overflow

2011-08-28 Thread saurabh singh
@avinash in that case the number will become negative,It wont remain a satisfactory input.Try to think logically and believe me once you get the logic you will relent why there is no option to delete previous mails..., On Sun, Aug 28, 2011 at 6:32 PM, Dave wrote: > @Avinash: Give an exam

[algogeeks] Re: Problem on overflow

2011-08-28 Thread Dave
@Avinash: Give an example. Dave On Aug 28, 7:00 am, "Avinash LetsUncomplicate.." wrote: > @dave i was saying if user input a .. he can enter a>intmax then how > to detect overflow? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to

Re: [algogeeks] Re: Problem on overflow

2011-08-28 Thread Avinash LetsUncomplicate..
@dave i was saying if user input a .. he can enter a>intmax then how to detect overflow? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send ema

Re: [algogeeks] Re: Problem on overflow

2011-08-28 Thread Prags
@Dave- Thank u frnd By the way, this question was asked recently in Tejas Network. On Sun, Aug 28, 2011 at 10:17 AM, Dave wrote: > @Avinash: maxint is the largest possible integer. There aren't any > integers greater than it. Thus, a can't be greater than maxint. For > example, if an int is

[algogeeks] Re: Problem on overflow

2011-08-27 Thread Dave
@Avinash: maxint is the largest possible integer. There aren't any integers greater than it. Thus, a can't be greater than maxint. For example, if an int is 32 bits, maxint = 2^31 - 1. Dave On Aug 27, 10:41 pm, "Avinash LetsUncomplicate.." wrote: > @dave i was saying if user enter a+b in which a

[algogeeks] Re: Problem on overflow

2011-08-27 Thread Dave
@Kunal: You are very kind. Dave On Aug 27, 12:58 pm, Kunal Patil wrote: > @Dave: Still your approach to solve the problem remains correct. > (subtracting a number from max possible value & then comparing this > difference with another number). So, no need to think that you were brain > dead (If

Re: [algogeeks] Re: Problem on overflow

2011-08-27 Thread Kunal Patil
@Dave: Still your approach to solve the problem remains correct. (subtracting a number from max possible value & then comparing this difference with another number). So, no need to think that you were brain dead (If you were, you would have posted a movie story here)..[?] Mathematically it is wrong

Re: [algogeeks] Re: Problem on overflow

2011-08-27 Thread dipit grover
Oops, I just saw that Dave had already corrected it. Net problem, sorry guys! On Sat, Aug 27, 2011 at 11:02 PM, dipit grover wrote: > I think you just need to reverse the comparison operators in Dave's earlier > post > > > On Sat, Aug 27, 2011 at 10:59 PM, Dave wrote: > >> @Abishek: I was brain-

Re: [algogeeks] Re: Problem on overflow

2011-08-27 Thread dipit grover
I think you just need to reverse the comparison operators in Dave's earlier post On Sat, Aug 27, 2011 at 10:59 PM, Dave wrote: > @Abishek: I was brain-dead in my earlier posting. Let me try again: > > If either number is zero, the sum will not overflow. > If the numbers have different signs, the

[algogeeks] Re: Problem on overflow

2011-08-27 Thread Dave
@Abishek: I was brain-dead in my earlier posting. Let me try again: If either number is zero, the sum will not overflow. If the numbers have different signs, the sum will not overflow. If both numbers are positive, overflow will occur if b > maxint - a. If both numbers are negative, overflow will

Re: [algogeeks] Re: Problem on overflow

2011-08-27 Thread Abhishek
@Dave: i didn't understand, suppose a=3, b=31000 and MaxInt=32000; you are saying if (MaxInt-a)>=b; then overflow will occur. but here condition is not satisfying. plz explain. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this

Re: [algogeeks] Re: Problem on overflow

2011-08-27 Thread Kunal Patil
@Dave: +1 for nice solution... :) On Sat, Aug 27, 2011 at 10:12 PM, Dave wrote: > @Avinash: What do you mean by "exceeding limit(already overflowed)"? > The number maxint is the limit. Every positive number is <= maxint. > > Dave > > On Aug 27, 10:31 am, "Avinash LetsUncomplicate.." 2...@gmail.

[algogeeks] Re: Problem on overflow

2011-08-27 Thread Dave
@Avinash: What do you mean by "exceeding limit(already overflowed)"? The number maxint is the limit. Every positive number is <= maxint. Dave On Aug 27, 10:31 am, "Avinash LetsUncomplicate.." wrote: > @dave if number a is entered exceeding limit(already overflowed) then > a goes negative(if a wa

Re: [algogeeks] Re: Problem on overflow

2011-08-27 Thread Avinash LetsUncomplicate..
@dave if number a is entered exceeding limit(already overflowed) then a goes negative(if a was entred just more than limit ) /a goes positive (if a was entred sufficiently more than limit ) maxint -a>=b concept fails Avinash Katiyar NIT Allahabad -- You received this message because you are s

[algogeeks] Re: Problem on overflow

2011-08-27 Thread Dave
@Prags: Pseudocode: If either number is zero, the sum will not overflow. If the numbers have different signs, the sum will not overflow. If both numbers are positive, overflow will occur if maxint - a >= b. If both numbers are negative, overflow will occur if maxint + a >= -b. Dave On Aug 27, 8:

Re: [algogeeks] Re: problem regarding output??

2011-08-10 Thread Puneet Chawla
It shows error in tc compiler We can't perform airthmetic opern on void* On Wed, Aug 10, 2011 at 10:08 AM, jagrati verma wrote: > (int *) it is derefrencing of any void pointer into > integer. > > -- > You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Re: problem regarding output??

2011-08-09 Thread jagrati verma
(int *) it is derefrencing of any void pointer into integer. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algog

[algogeeks] Re: problem regarding output??

2011-08-09 Thread Ankuj Gupta
C++ will not allow void pointer to increment. But in C we can perform it where void will be treated as char* http://stackoverflow.com/questions/3523145/pointer-arithmetic-for-void-pointer-in-c On Aug 9, 6:39 pm, UMarius wrote: > ++ on a void* will increase the address by 1 byte.  ++ on a type* wi

[algogeeks] Re: problem regarding output??

2011-08-09 Thread UMarius
++ on a void* will increase the address by 1 byte. ++ on a type* will increase the address by sizeof(type) bytes. As if the initial pointer were an array of "type" On Aug 9, 2:49 pm, Rajesh Kumar wrote: > why j and k  point different location? > > #include > main() > { > int a=10,*j; > void *k;

[algogeeks] Re: problem tree minimum sum in binary

2011-07-26 Thread WgpShashank
Guys this problem generated lot of discussion in computer science as ist Euler Problem as it involves maths stuff rather then considering tree (it wont work check below link for detail ) or applying computer science . Also problem is already famous (Euler problem ) as we have to find the ma

Re: [algogeeks] Re: Problem: Longest Increasing Seq code

2011-07-15 Thread surender sanke
p[i] maintains previous index from which b[i] has reached longest sequence till i. to get the actual list of non-decrease sequence, p has to be traversed through back indices for (u = b.size(), v = b.back(); u--; v = p[v]) b[u] = v; surender On Sat, Jul 16, 2011 at 9:06 AM, Neeraj Gupta wrote: >

[algogeeks] Re: Problem: Longest Increasing Seq code

2011-07-15 Thread Neeraj Gupta
Hi > Can anyone help me in understanding the following code > http://www.algorithmist.com/index.php/Longest_Increasing_Subsequence.cpp > > I am not able to understand what is the exact purpose of vector p in the > above mentioned code. > A little detail explanation will be helpful. > > I have alre

[algogeeks] Re: Problem

2011-05-11 Thread Don
For small numbers, trial division would work. Be sure to only divide by prime numbers. When you find one which divides your target, increment your counter and divide the target by that number as many times as it works. Then go on to the next prime. When the prime squared is larger than the target,

[algogeeks] Re: Problem regarding MySql server Installation

2011-04-29 Thread ligerdave
Sorry, but this isn't a mysql group. all discussions need to be algorithm related. On Apr 28, 3:04 pm, Aniket wrote: > I was trying to install mysql 5.5. in Windows XP.After installation > during configuration phase when there was to apply security settings I > m always getting an error > > Error

[algogeeks] Re: Problem regarding MySql server Installation

2011-04-29 Thread bittu
As i remeber you can do this on command prompt type i am assuming u have installed & configured mysql "mysql -u username -p password" i think u shoud have google it Thanks & Regards Shashank Mani>> " The Best Way to escape Fromm problem is Solve It" CSE,BIT Mesra -- You received this message

[algogeeks] Re: Problem regarding MySql server Installation

2011-04-29 Thread bittu
i forget to say that every tool has its own site for documentation & help check it it out http://dev.mysql.com/doc/refman/5.5/en/default-privileges.html Thanks Shashank -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group,

[algogeeks] Re: Problem; print the largest subset of negative number in array of integers

2011-04-26 Thread sravanreddy001
How about the following way.. where you can save some space. but before that.. you meant, your application will need O(n) space for the recursion only right? in that case, instead of the recursion, try this approach. set start, length = 0, tempStart, tempLenght =0 set tempStart = i_value incre

[algogeeks] Re: Problem from ACM ICPC 2010_2

2011-01-09 Thread rgap
Thanks, i finished it. :) it wasdist[i] + dist[j] - 2*dist[lca(i, j)] "this problem is difficult" :( http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4809 I dont have idea how to solve it. -- You received this message because you are subscribed to the Google Groups "Alg

[algogeeks] Re: Problem from ACM ICPC 2010_2

2011-01-09 Thread juver++
Run dfs/bfs from the root (node 0). Store distance from the root to each node at the node's data. Then the final path's weight between i and j is: dist[i] + dist[j] - dist[lca(i, j)]. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post

[algogeeks] Re: Problem from ACM ICPC 2010

2011-01-09 Thread juver++
There are 4 kids). So 1, 2, 3 are connected into a circle. There is no place for the remaining 4-th) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this gr

[algogeeks] Re: Problem from ACM ICPC 2010

2011-01-08 Thread Jammy
I wondered that too...seems kid 3 gets too many wishes On Jan 8, 8:21 pm, bhawana goel wrote: > In the 3rd test case, how come the answer is Yes. 1,2 and 3 are > forming a cycle. > > On Jan 8, 1:19 pm, juver++ wrote: > > > > > > > > > Also, you may use hash_set and hash_map if such exists in you

[algogeeks] Re: Problem from ACM ICPC 2010

2011-01-08 Thread bhawana goel
In the 3rd test case, how come the answer is Yes. 1,2 and 3 are forming a cycle. On Jan 8, 1:19 pm, juver++ wrote: > Also, you may use hash_set and hash_map if such exists in your language. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To

[algogeeks] Re: Problem from ACM ICPC 2010

2011-01-08 Thread juver++
Also, you may use hash_set and hash_map if such exists in your language. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks

[algogeeks] Re: Problem from ACM ICPC 2010

2011-01-08 Thread juver++
Use map > whichs maps vertex and all its neighbors. You should use bfs only to find if there is cycle (with a shape of circle). set is useful to keep track of visited vertices. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this g

[algogeeks] Re: Problem from ACM ICPC 2010

2011-01-08 Thread rgap
Hi.. thanks for your response. The number of kids: 3 <= K <= 10^9 I cant declare an array: long long A[10]; and how does dfs or bfs finds the components of the graph? because i have to verify if there is a cycle in all the components. -- You received this message because you are subscr

[algogeeks] Re: Problem from ACM ICPC 2010

2011-01-08 Thread juver++
Just got AC for this problem. Here is simple solution: 1. Calculate degree for each vertex. If there is a degree > 2, then answer is No. You may use hash_map or map here. 2. So at this step we don't have any verticies with 3 and more edges, only <= 2 are allowed. Though, we should check if there

[algogeeks] Re: Problem with Virtual Function

2010-06-13 Thread souravsain
Guys Lets keep discussions in t his group limited to Algos and problems neutral to any language. @akshay: Request you to post these C++ language specific questions to those language specific groups. This will not only help this group remain confined to its core purpose but will help you get better

[algogeeks] Re: Problem in code

2008-02-23 Thread Vishal
Can we just not post the code here for debugging? This group more related to algorithms than implementations. If your code is not working, use debugger. On Sat, Feb 23, 2008 at 6:22 AM, monty 1987 <[EMAIL PROTECTED]> wrote: > Find out why this program is not working which converts list > represen

[algogeeks] Re: Problem with conditional statement

2007-06-18 Thread Dhyanesh (ધયાનેશ)
It says " If there is more than one solution print the pair with smaller X value." Also I believe for a value of X only one of the 2 Y values might work, not sure though. -Dhyanesh On 6/18/07, mukesh tiwari <[EMAIL PROTECTED]> wrote: > Hi everybody i am trying to solve problem > http://acm.uva.

[algogeeks] Re: problem with string class in c++

2007-02-08 Thread nima
hi :) and welcome to C++ there's some problems in your code... 1. the string temp has the length 0 and you cannot use subscript operator to access for example temp[3] or temp[2] or . first in the declaration of temp you can initialize it by x (just to adjust the size to the appropriate) st

[algogeeks] Re: problem regarding lexicographic path

2006-12-14 Thread Minhaz Ul-Alam
well mukesh , I solved the problem iteratively from right to left and filling up an arry. Here is my code. I think Lago Haryanto was right. you have to select and find out the lexicographically shortest path greedily. Minhaz code: /* @JUDGE_ID: 55890 116 C++*/ #include void min3(int,int); vo

[algogeeks] Re: problem regarding lexicographic path

2006-12-13 Thread mukesh tiwari
hi Lego Haryanto i tried ur metoh but still not working ...here is my code and i m tired with this program . i am not getting even a single method to find lexicographic shortest path. #include int min1(int k,int m,int n) { int min;

[algogeeks] Re: problem regarding lexicographic path

2006-12-06 Thread Lego Haryanto
When you are at one column and try to decide which row in the next column is best, ... you can add another check in case there are more than one row with best values right, and pick the row with the smaller value. I think the only gotcha there is that the row can wrap around from the last row to 0

[algogeeks] Re: Problem 4.2 from "Introduction to algorithms"

2006-12-01 Thread W Karas
wrb wrote: > in arrange 1..n there are n different numbers. how can you fill A[1..n] > without any one of them? That occurred to me as well, but I assumed that it must be allowed that for A[i] == A[j], i != j because otherwise it would be impossible for there to be any missing numbers. > > > >

[algogeeks] Re: Problem 4.2 from "Introduction to algorithms"

2006-11-30 Thread wrb
in arrange 1..n there are n different numbers. how can you fill A[1..n] without any one of them? 2006/12/1, W Karas <[EMAIL PROTECTED]>: > > > Norbert wrote: > > Hi, please help me solve this problem. It's something like that: given > > an array A[1...n] filled with different integers in range [

[algogeeks] Re: Problem 4.2 from "Introduction to algorithms"

2006-11-30 Thread W Karas
Norbert wrote: > Hi, please help me solve this problem. It's something like that: given > an array A[1...n] filled with different integers in range [1...n], > find a missing number. The only operation which you can use is > get_ith_bit_from_pos_n(i, n) = i'th bit of A[n]. This can be solved in > O

[algogeeks] Re: Problem 4.2 from "Introduction to algorithms"

2006-11-17 Thread Arun
neat solution :) On 11/17/06, Dhyanesh (ધયાનેશ) <[EMAIL PROTECTED]> wrote: > > 1) Scan through the array counting number of 0s and 1s in MSB, as well as > separating the 0s into an array arr0 and 1s into an array arr1 (if you do > not want to use extra space you can use splitting around pivot pass

[algogeeks] Re: Problem 4.2 from "Introduction to algorithms"

2006-11-17 Thread Dhyanesh (ધયાનેશ)
1) Scan through the array counting number of 0s and 1s in MSB, as well as separating the 0s into an array arr0 and 1s into an array arr1 (if you do not want to use extra space you can use splitting around pivot pass of quicksort). 2) You would know how many 0s and 1s should be present in MSB for th

[algogeeks] Re: Problem 4.2 from "Introduction to algorithms"

2006-11-17 Thread Norbert
On 11/17/06, Arun <[EMAIL PROTECTED]> wrote: > > the original problem if the array is unsorted, u can do it, by counting the > number of 1's (and hence 0's), in each bit position. (i.e vertically scan > thru all the numbers once for each bit position). given any n, u know how > many 1's shud be p

[algogeeks] Re: Problem 4.2 from "Introduction to algorithms"

2006-11-17 Thread Arun
the original problem if the array is unsorted, u can do it, by counting the number of 1's (and hence 0's), in each bit position. (i.e vertically scan thru all the numbers once for each bit position). given any n, u know how many 1's shud be present in msb,2nd msb and so-on. based on this u can find

[algogeeks] Re: Problem 4.2 from "Introduction to algorithms"

2006-11-17 Thread Norbert
extract(i, n) - i'th bit from position n in an array A - i'th bit of A[n] On 11/17/06, Idris <[EMAIL PROTECTED]> wrote: > > > Is this extracting i'th bit from a[X] or just extracting Integer from i > th index of an array??? > > if its the later, then get the number and sum up by using OR > operat

[algogeeks] Re: Problem 4.2 from "Introduction to algorithms"

2006-11-17 Thread Idris
Is this extracting i'th bit from a[X] or just extracting Integer from i th index of an array??? if its the later, then get the number and sum up by using OR operation not sure:-) then subtract it from n(n+1)/2="missing Number" --~--~-~--~~~---~--~~ You rec

[algogeeks] Re: Problem

2006-11-09 Thread Satish
The minimum case would be if you can place all these 4 input rectangles in the vertical plane of the resultant recatangle, and along its diagonal. So suppose dimensions of 4 rectangles are (x1,y1),(x2,y2),(x3,y3),(x4,y4) and of the resultant rectangle is (x,y). Then solution is all (x,y) that sa

[algogeeks] Re: Problem

2006-11-08 Thread Spiritus
Yeah, its from ioi. 1)the solution is on their site. basically there are like 6 ways to put rectangles together given their order and orientation. so, you just loop through all permutations and orientation, and try each of the 6 possibilities(which are shown on their site), and select a minimum.

[algogeeks] Re: Problem

2006-11-07 Thread mohamad momenian
Yes that is from ioi95 | INPUT.TXT | | OUTPUT.TXT ||___| ||| 1 2   |      | 40 || 2 3   |  | 4 10   || 3 4   |  | 5 8    || 4 5   |      || |___|    Example input

[algogeeks] Re: Problem

2006-11-07 Thread Manish Garg
it will be better if u will give at least one sample input and output. On 11/7/06, mohamad momenian <[EMAIL PROTECTED]> wrote: Hi   i have a problem please help me The input of problem is : width and height of 4 rectangle that is between 1,50 and the we must calculate width and height of all

[algogeeks] Re: Problem

2006-11-07 Thread Atamyrat Hezretguliyew
On 11/7/06, Malay Bag <[EMAIL PROTECTED]> wrote: > I did not get the point:- > "we must calculate width and height of all of rectangles that can cover this > 4 rectangles and it's area become minimum" > can you give some example? I think this problem is from IOI95 http://olympiads.win.tue.nl/ioi9

[algogeeks] Re: Problem

2006-11-07 Thread Malay Bag
I did not get the point:-"we must calculate width and height of all of rectangles that can cover this 4 rectangles and it's area become minimum"can you give some example? On 11/7/06, mohamad momenian <[EMAIL PROTECTED]> wrote: No they can't over lap   thank you for your attention  On 11/7/06, shis

[algogeeks] Re: Problem

2006-11-07 Thread mohamad momenian
No they can't over lap   thank you for your attention  On 11/7/06, shisheng li <[EMAIL PROTECTED]> wrote: Can the 4 overlap?   From: algogeeks@googlegroups.com [mailto: algogeeks@googlegroups.com] On Behalf Of mohamad momenianSent: Tuesday, November 07, 2006 4:09 PM To: algogeeks@googlegro

[algogeeks] Re: Problem

2006-11-07 Thread shisheng li
Can the 4 overlap?   From: algogeeks@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of mohamad momenian Sent: Tuesday, November 07, 2006 4:09 PM To: algogeeks@googlegroups.com Subject: [algogeeks] Problem   Hi   i have a problem please help me The input

[algogeeks] Re: Problem

2006-04-07 Thread wade
eizhao... wrote > wade wrote >> [EMAIL PROTECTED] wrote: >>> Is the solution always x = N-4, y = N-3, z = N-2 ? >>> Suppose we are looking for x and y to minimize the sum. >>> Sum = a[i]*x + a[j]*y, where 0 <= i <= x < j <= y <= N. >>> It is always bigger than a[i]*x + a[j]*x, because x < y and al

[algogeeks] Re: Problem

2006-04-06 Thread [EMAIL PROTECTED]
Hi, 0 < x < y < z < N-1 is the requirement. Lei --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this gro

[algogeeks] Re: Problem

2006-04-06 Thread wade
[EMAIL PROTECTED] wrote: > Is the solution always x = N-4, y = N-3, z = N-2 ? > > Suppose we are looking for x and y to minimize the sum. > Sum = a[i]*x + a[j]*y, where 0 <= i <= x < j <= y <= N. > It is always bigger than a[i]*x + a[j]*x, because x < y and all numbers > are positive. > We have t

[algogeeks] Re: Problem

2006-04-05 Thread [EMAIL PROTECTED]
Is the solution always x = N-4, y = N-3, z = N-2 ? Suppose we are looking for x and y to minimize the sum. Sum = a[i]*x + a[j]*y, where 0 <= i <= x < j <= y <= N. It is always bigger than a[i]*x + a[j]*x, because x < y and all numbers are positive. We have to have a y so when y is the last one, t

[algogeeks] Re: Problem

2006-04-04 Thread Arunachalam
Hi,    How come you are saying this as a brute force method. We are storing the results of  previous computation in the dp array so that we don't compute the already computed values again and again.   I think this is of order n^3.   regards Arunachalam.  On 4/4/06, learner <[EMAIL PROTECTED]>

[algogeeks] Re: Problem

2006-04-04 Thread learner
This is a brute force method. Is there any method by which we could reduce the no. of computations , or some early checks could be made for reducing the execution time of the algorithm. --~--~-~--~~~---~--~~ You received this message because you are subscribed to

[algogeeks] Re: Problem

2006-04-04 Thread Arunachalam
Well,    we can solve it using Dynamic Programming.   I am giving the gist of my logic.   Lets call x,y and z as split points   1. Find the cost of x, for all positions in 1..n-3 and store it 2. For each postion in 2..n-2(Y) find the x such that cost is minimum and store it 3. For each Positio

[algogeeks] Re: problem about MATROID...

2006-03-11 Thread gcet
anybody can think on this problem? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this group, send email

[algogeeks] Re: Problem with recursion on C

2005-11-28 Thread Vishal
If you want to print the sequence in order and also want to use recursion, then keep a global variable N which varies from 1 to 3 (if you want max length of string as 3). In permute(n) method, change condition to 'if (n   int N;   void permute(int n){       for(int i=0; i<5; ++i){               A[n

[algogeeks] Re: Problem with recursion on C

2005-11-28 Thread Abhi
Hi gaijinco, I think the result which you want can be best achieved just using N+1 loops. Also the non-recursive programs are much faster to execute and easier to understand. Regards, -Abhi

[algogeeks] Re: Problem with recursion on C

2005-11-27 Thread gaijinco
>> Also note that this is one of the worse ways of doing >> permutations - and that the iterative way uses much less memory (recursion >> frames) - if u see what I mean. What I was needing is something like this: Given an N number I needed to print the following pattern: if N = 2 A B AA AB BA

[algogeeks] Re: Problem with recursion on C

2005-11-21 Thread siva
Hi gaijinco, Your code looks fine. Only thing you are missing is a temp array. Instead of printing the element in stdout. Just populate the corresponding element in the array. ANd all the element are generated print out all the elements in the temp array. Thanks, Siva

[algogeeks] Re: Problem with recursion on C

2005-11-20 Thread Vishal
Gaijinco, Your method is correct except for one small bug. You will call permute method only for values 0,1 and 2 (since array length is 3). So the condition should be  if (n<2) and not if (n<3). Correct code : void permute(int n){        for(int i=0; i<5; ++i){                A[n]=i+1;  

[algogeeks] Re: Problem with recursion on C

2005-11-20 Thread Ulan
With STL a simpler solution is possible: #include #include using namespace std; int main() { int a[] = {1, 2, 3, 4, 5}; do { for (int i = 0; i < 5; ++i) cout << a[i] << " "; cout << endl; }while(next_permuta

[algogeeks] Re: Problem with recursion on C

2005-11-20 Thread [EMAIL PROTECTED]
No. It's illegal in any language. You're missing a closing brace.

[algogeeks] Re: Problem with recursion on C

2005-11-20 Thread Mayur
Hi Gaijinco, What is it that you want to do? Generate permutations? Or print a table of values 111, 112, etc.. (because that's what your first program is doing)? If the former is what you want to do: #include inline void swap( int &a, int &b ) { int c = a; a = b; b =c; } void permute(int values[

  1   2   >