@anurag, does the vector's next permutation return next higher
element?
On Dec 6, 8:10 am, Anurag Sharma wrote:
> In context of C++
>
> 1. Populate the digits of the given number in a vector V
> 2. call next_permutation() on V
> 3. print the vector [?]
>
> Thanks,
> Anurag Sharma
> +91-8
Given : 4 2 8 9 5 1 9
sort the array.
sorting: 1 2 4 5 8 9 9
for ( i = 0 ; i < len ; i++)
{
if( i != len-1 )
{
if (arr[i]==arr[i+1])
{
printf("\nfound repeated element\n");
break;
}
}
}
On Mon, Nov 28, 2011 at 1:
I am getting a lot of tle's for this problem.
https://www.spoj.pl/problems/BUGLIFE/
Here is my code
#include
#include
#include
using namespace std;
int g[2001][2001];
int color[2001];
short stack[5001];
int bugs, rel;
int inline complement(int n);
bool inline dfs();
int v1, v2;
int main()
{
@sourabh singh..
Hey u don't need an example... I see a check "sum > max" in ur code to
calculate the max value, ryt ? Now ur initial value of max is set to
1. That means ur always assuming that the value whose closest is to be
found is >= 1 , which is incorrect. What do you think ?
On Dec 6, 12:
actually there are no random numbers, they are always "psuedo random". the
criteria can be anything to generate. one is to take the current time.
At any moment, time can't be same hence the numerical value of "current
time" provides a great help in that direction.
although to generate random numbe
In context of C++
1. Populate the digits of the given number in a vector V
2. call next_permutation() on V
3. print the vector [?]
Thanks,
Anurag Sharma
+91-8712218874
On Tue, Dec 6, 2011 at 2:23 AM, sourabh wrote:
> This problem is a direct implication of "next_permutation" define
This problem is a direct implication of "next_permutation" defined in C
++ STL algorithms.
1) From the end, keep decrementing till A[i] < A[i+1]..
2) Now, find the closest element , greater than equal, to A[i] in A[i
+1 ... n]. Say, the index of the found element is "j".
3) Swap (A[i], A[j])
4) Re
The "rand" function is implementation defined, so it doesn't work the
same for every compiler. Most of them use a pseudo-random generating
function such as linear congruential generators, lagged Fibonacci
generators, and linear feedback shift registers. Poor generators are
very common and have bad
Hmm here is a thought.
In the given number, check the second digit from the left.
if it is the maximum, find the digit that is the next greater digit from
the left most digit.
append it to the start and append all the other numbers in sorted order.
if the second from left isn't the largest, find
@ sourabh tried some cases its working on -ve as well. pls post some
case in which it might not work.
On 12/5/11, sourabh wrote:
> @sourabh..
>
> I don't think it will work for all the cases.. did u consider negative
> integers as well... what i can understand from the above code is that
> u have
@sourabh..
I don't think it will work for all the cases.. did u consider negative
integers as well... what i can understand from the above code is that
u have taken 2 pointers of which one points to the beginning of the
subarray and other one at the end of the subarray and u r shifting the
pointer
So there is no algorithm involved in it?
On Dec 5, 10:14 pm, saurabh singh wrote:
> In linux they are picked up from /dev/random which is a pseudo device
> generating random numbers on the basis of noise produced by the movements
> of the mouse/touchpad...(So coool:)) check out *cat /dev/rand
Given a number,find the next higher number using the same digits in the
number.
eg: 15432 :: 21345
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this grou
In linux they are picked up from /dev/random which is a pseudo device
generating random numbers on the basis of noise produced by the movements
of the mouse/touchpad...(So coool:)) check out *cat /dev/random*
On Mon, Dec 5, 2011 at 9:28 PM, Prakash wrote:
> Anyone please explain how rand() f
Anyone please explain how rand() function is defined and how it
works?
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+u
Congrats :) :)
On Mon, Dec 5, 2011 at 10:48 AM, kumar raja wrote:
> Thank u sir
>
>
> On 5 December 2011 09:27, Dave wrote:
>
>> @Kumar. Congratulations. Happy to be of help.
>>
>> Dave
>>
>> On Dec 4, 12:49 pm, kumar raja wrote:
>> > I am selected in Oracle Server Technologies today
>> >
>> >
@Carl: You can generate the constants the first time the procedure is
called. There is no need to do them every time. So the first call
would be O(wordsize) but subsequent calls are O(1).
Dave
On Dec 5, 10:28 am, Carl Barton wrote:
> Sorry, I was being a bit vague. I meant what would the time co
Sorry, I was being a bit vague. I meant what would the time complexity be
then?
As I understand your Constant time is Dependant on the constant pre
computation you do, which is no longer the case when you generalise
On 5 December 2011 16:14, Dave wrote:
> @Carl: Of course. For any given word siz
ya hashing cud be a bttr soln bt wat cud be hash fn den???
Regards,
PAYAL GUPTA.
On 11/30/11, Ankuj Gupta wrote:
> We can do it by hashing. hash the 2-d array and then search for 1 d array
> in the hash table.
>
> --
> You received this message because you are subscribed to the Google Groups
> "
@Carl: Of course. For any given word size, extend the tables of powers
of 2 and of 3 and change the for loop limit.
Dave
On Dec 5, 9:36 am, Carl Barton wrote:
> Ah I see, in which case could you not generalise your solution for all
> integers?
> By taking into account the size of words on the co
Ah I see, in which case could you not generalise your solution for all
integers?
By taking into account the size of words on the computer for example?
On 5 December 2011 15:09, Dave wrote:
> @Carl: Yes, as coded, my algorithm is for 32-bit integers. But the
> original poster asked for a soluti
@Carl: Yes, as coded, my algorithm is for 32-bit integers. But the
original poster asked for a solution using bit manipulation, and
modulus and division are arithmetic operations, not bit operations.
Dave
On Dec 5, 8:56 am, Carl Barton wrote:
> @Dave Yours only works for a certain subset of all
@Dave Yours only works for a certain subset of all possible powers or 3
doesn't it? So WgpShashank's would be more general?
On 5 December 2011 14:30, Dave wrote:
> @WgpShashank: Yours is an O(log n) solution. Mine is O(1).
>
> Dave
>
> On Dec 5, 6:21 am, WgpShashank wrote:
> > @SAMMM have a lo
@WgpShashank: Yours is an O(log n) solution. Mine is O(1).
Dave
On Dec 5, 6:21 am, WgpShashank wrote:
> @SAMMM have a look
>
> * *solution is to keep dividing the number by 3, i.e, do n = n/3
> iteratively. In any iteration, if n%3 becomes non-zero and n is not 1 then
> n is not a power of 3, o
@SAMMM have a look
* *solution is to keep dividing the number by 3, i.e, do n = n/3
iteratively. In any iteration, if n%3 becomes non-zero and n is not 1 then
n is not a power of 3, otherwise n is a power of 3
check it out ? http://codepad.org/863ptoBE
Thanks
Shashank
Computer Science
BIT Me
Hmm that too be should be impossible but the problem is how will you give
the input of real numbers on tape?
Notice however that we can always make a restricted machine that works on a
subset of real numbers.(For example integers)
On Mon, Dec 5, 2011 at 4:37 PM, Aamir Khan wrote:
>
>
> On Mo
@piyuesh 3-Sum is not exponential ? its quadratic , check wiki for refrence
?
On Mon, Dec 5, 2011 at 5:36 PM, Piyush Grover wrote:
> As I mentioned earlier solution with exponential time-complexity is the
> obvious one. Is there any way to solve this problem by greedy/Dynamic algo?
>
>
> On Mon,
As I mentioned earlier solution with exponential time-complexity is the
obvious one. Is there any way to solve this problem by greedy/Dynamic algo?
On Mon, Dec 5, 2011 at 5:24 PM, WgpShashank wrote:
> @piyuesh , Saurabh isn't 3-Sum Suffics Here ?
>
> Another thought problem can also be thought by
@piyuesh , Saurabh isn't 3-Sum Suffics Here ?
Another thought problem can also be thought by generating power set of
given set e.g. if set has n elemnts its power set has 2^n elements , then
finds the set that has sum up yo given weight isn't it ? hope you know how
to find power set efficien
@ mohit my first post on here. this solution got ac in spoj
main()
{
unsigned int n,m,sum,max,i,j;
sum=0;max=1;
n=in.ReadNextUInt();
m=in.ReadNextUInt();
unsigned int *a = new unsigned int[n];
unsigned
On Mon, Dec 5, 2011 at 4:33 PM, saurabh singh wrote:
> I said *uncountably infinite.* *Integers are countably infinite.* *A
> countably infinite set will require finite number of states as we can
> arrange them in order.*
What about addition of real numbers then. Real numbers are uncountably
inf
I said *uncountably infinite.* *Integers are countably infinite.* *A
countably infinite set will require finite number of states as we can
arrange them in order.*
On Mon, Dec 5, 2011 at 4:26 PM, Aamir Khan wrote:
>
>
> On Mon, Dec 5, 2011 at 3:31 PM, saurabh singh wrote:
>
>> I was wondering ca
On Mon, Dec 5, 2011 at 3:31 PM, saurabh singh wrote:
> I was wondering can we design a machine(Even hypothetical) that can find
> a *perfect square root *of any integer thats given to it.
> My logic why we can't is since there are uncountably infinite real
> numbers, there will be uncountably in
Which one of the following is true for a CPU having a single interrupt
request line and a single interrupt grant line?
a)Neither vectored interrupt nor multiple interrupting devices are
possible.
b)Vectored interrupts are not possible but multiple multiple
interrupting devices are possible.
c)Vect
I was wondering can we design a machine(Even hypothetical) that can find a
*perfect square root *of any integer thats given to it.
My logic why we can't is since there are uncountably infinite real numbers,
there will be uncountably infinite numbers requiring infinite states on a
turing machine.Bu
As such there's no significance for Vi, it's just to show that objects are
not identical. We don't need to maximize on V. For the sake of problem you
can ignore it. We can use the sum of values for other purpose.
Take an examole: S= {1, 2, 3, 4, 5} are weights (I am not using Values)
. Wmax = 8
S
@ Piyush..
I have a doubt... Is there any significance of the value Vi, if yes
then can u give an example.
If not, then is your question about finding all maximum subsets where
the addition of the weights results in maximum (each weight being
considered only once)...
Say for ex-
The max weight is
Yeah but there's one more condition where it says if subset x is a
solution then all the subsets of x will not be part of the solution.
It should make some difference, exponential time solution is an obvious one.
On Mon, Dec 5, 2011 at 2:16 PM, saurabh singh wrote:
> The possibility is ruled ou
The possibility is ruled out by your question itself.There are exponential
subsets of a set,so finding all subset is not possible in polynomail time.
A backtracking approach is what you should think on,
On Mon, Dec 5, 2011 at 12:51 PM, Piyush Grover wrote:
> Given a set S of objects having weigh
39 matches
Mail list logo