[algogeeks] Re: spoj problem EASYMATH

2012-09-27 Thread gaurav yadav
thanx :)

-- 
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/-/iy_uho_bmMYJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: 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 view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/3H3O2K4KBBMJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Re: spoj problem : POKER

2012-06-18 Thread Pranjal Patil
Your code fails on one of the test cases like 5H 6H 7H 8H 9H.
it should give "straight flush "instead of " flush", Think of all such
cases are change accordingly ..

On Mon, Jun 18, 2012 at 10:01 PM, Mayank Singh
 wrote:
> it also ran successfully on ideone.com
> plz help me
> i am classifying the card in two parts:
> one with same suit
> and other with different suit...
>
> plz let me know if futher explanation is needed abt the code
>
> help me regarding this..
> 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.

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



[algogeeks] Re: spoj problem : POKER

2012-06-18 Thread Mayank Singh
it also ran successfully on ideone.com
plz help me
i am classifying the card in two parts:
one with same suit
and other with different suit...

plz let me know if futher explanation is needed abt the code

help me regarding this..
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.



Re: [algogeeks] Re: spoj problem

2012-06-13 Thread Sourabh Singh
@  saurabh singh :

 what algorithm can be used ??
 coz.. i did it by simple observation.

 1)  just take any sequence of numbers.
 2)  write it's first 5-6 xor round's.
 3)  now luk for some pattern.

 u'll get the answer  : )

On Wed, Jun 13, 2012 at 9:46 PM, saurabh singh  wrote:

> No this is fair enough.It directly involves algorithm.
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT
> blog:geekinessthecoolway.blogspot.com
>
>
>
> On Thu, Jun 14, 2012 at 4:28 AM, shiv narayan 
> wrote:
>
>> will be better if you post on spoj forums.!!
>>
>>
>> On Wednesday, 13 June 2012 01:40:36 UTC+5:30, gaurav yadav wrote:
>>>
>>> plz nyone explain how to approach this problem..
>>> http://www.spoj.pl/problems/**XORROUND/
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/algogeeks/-/lvClpFbMOwgJ.
>>
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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] Re: spoj problem

2012-06-13 Thread saurabh singh
No this is fair enough.It directly involves algorithm.
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Thu, Jun 14, 2012 at 4:28 AM, shiv narayan wrote:

> will be better if you post on spoj forums.!!
>
>
> On Wednesday, 13 June 2012 01:40:36 UTC+5:30, gaurav yadav wrote:
>>
>> plz nyone explain how to approach this problem..
>> http://www.spoj.pl/problems/**XORROUND/
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/lvClpFbMOwgJ.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] Re: spoj problem

2012-06-13 Thread shiv narayan
will be better if you post on spoj forums.!! 

On Wednesday, 13 June 2012 01:40:36 UTC+5:30, gaurav yadav wrote:
>
> plz nyone explain how to approach this problem.. 
> http://www.spoj.pl/problems/XORROUND/ 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/lvClpFbMOwgJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Re: spoj problem

2012-05-15 Thread ashish pant
@lucifer
nice approach for calculating median.. thanks for the help

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



[algogeeks] Re: spoj problem

2012-05-13 Thread Lucifer

O(n) approach for finding the height of the stacks..
-
First take 2 arrays A[n] and B[n],
where A keeps track of the no. of times a start index(the start query
index) occurs.
and B keeps track of the no. of times a end index(the end query index)
occurs.

Also,
take an array C[n] to store height of each stack..

To calculate the height of a particular stack we can use the following
logic:

As we know that if the end index is say 'R' then start index would be
<= 'R'.
Hence, for a given stack index 'X' , we can calculate its height by
using the following equation:

C[X] = (no. of start indices strictly lesser than (<) 'X') - (no. of
end indices strictly lesser than (<) 'X') + A[X]

---

O(K) approach to get the median stack

As there are only 'K' instructions, it implies that the height of the
stack will be <='K'.

Hence, let take an array S[K+1] ( 0..K) to keep track of the no. of
stacks with height 'i'(say) given by S[i]..
To do this we have to run through array C and generate S, as follows:
for(int i =0; i  S[i])
 x= x- S[i];
  else
  break;
}

// after the loop breaks 'i' will be the height of the median stack..




On May 13, 8:42 pm, Krishnan  wrote:
> @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] Re: spoj

2012-02-16 Thread Kartik Sachan
> @atul by doing through link list it will give TLEu have to derive some
> kind of formula .. and till now i am unable to find that
> 
>

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

2012-02-16 Thread atul anand
@ pavan : thanks...

@utkarsh : please find attached code..please le me knw if any case fail

On Thu, Feb 16, 2012 at 7:02 PM, pavan  wrote:

> yeah the results are correct for the given inputs
>
> On Feb 16, 1:03 am, atul anand  wrote:
> > if i have understood the problem correctly...
> > you please confirm the answers i am getting for the given inputs:-
> >   result
> > 1) 1 2 3 4 54
> > 2) 1 2 3 4 5 6 5
> > 3) 1 2 3 4 5 6 7  4
> > 4) 1 2 3 4 5 6 7 8   8
> >
> > On Wed, Feb 15, 2012 at 11:38 PM, Dheeraj Sharma <
> >
> > dheerajsharma1...@gmail.com> wrote:
> > > yeah..we need to calculate some formula
> >
> > > On Wed, Feb 15, 2012 at 10:21 PM, pavan  wrote:
> >
> > >> @Utkarsh: yeah it is josephsus problem with a slight change.using
> > >> a linked list will give u TLE i guess.
> >
> > >> On Feb 14, 10:36 pm, vickywiz  wrote:
> > >> > in 1 2 3 4 5 6...o/p "ll b 5
> >
> > >> --
> > >> You received this message because you are subscribed to the Google
> Groups
> > >> "Algorithm Geeks" group.
> > >> To post to this group, send email to algogeeks@googlegroups.com.
> > >> To unsubscribe from this group, send email to
> > >> algogeeks+unsubscr...@googlegroups.com.
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/algogeeks?hl=en.
> >
> > > --
> > > *Dheeraj Sharma*
> >
> > >  --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to algogeeks@googlegroups.com.
> > > To unsubscribe from 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.

# include 
# include 
struct node
{
   int data;
   struct node *link;
};
struct node *insert(struct node *p, int n)
{
   struct node *temp;

   if(p==NULL)
   {
	 p=(struct node *)malloc(sizeof(struct node));
	if(p==NULL)
	{
		 printf("Error\n");
		 exit(0);
	 }
	 p-> data = n;
	  p-> link = p;
  }
  else
  {
	 temp = p;

	 while (temp-> link != p)
		temp = temp-> link;
	 temp-> link = (struct node *)malloc(sizeof(struct node));
	 if(temp -> link == NULL)
	 {
		  printf("Error\n");
	 }
	temp = temp-> link;
	temp-> data = n;
	temp-> link = p;
	 }
	 return (p);
   }
   void printlist ( struct node *p )
   {
  struct node *temp;
  temp = p;
  if(p!= NULL)
  {
  do
  {
		printf("%d\t",temp->data);

		temp=temp->link;
  } while (temp!= p);
   }
   else
  printf("The list is empty\n");
   }
   struct node *del(struct node *start,int val)
   {
	struct node *p=NULL;
	struct node *tmp=NULL;
	int flag=0;
	if(start->link==start)
	{
		return start;

	}
	p=start;

	while(p->link!=start)
	{
		if(p->link->data==val)
		{
			tmp=p->link;
			p->link=p->link->link;
			tmp=NULL;
			free(tmp);
			flag=1;
			break;

		}
		 p=p->link;

	}
	if(p->link->data==val && flag==0)
	{
		tmp=p->link;
		p->link=start->link;
		tmp=NULL;
		free(tmp);
		start=p->link;

	}
	return start;

   }

   void main()
   {
  int n;
  int x;
  int total,shoot,cnt=1,flag=0,j=1;
  struct node *start = NULL ,*tmp=NULL;
  printf("Enter the nodes to be created  = ");
  scanf("%d",&n);
  printf("\n\n");
  total=n;
  while ( n-- > 0 )
  {
	 start = insert ( start, j );
	 j++;
  }

  shoot=1;
  printf("\n\nList Formed\n\n");
  printlist(start);
  printf("\n\n");
  while(total>1)
  {
		cnt=1;
		while(cntlink;
			cnt++;

		}
		start=del(start,start->data);
		total--;
		shoot++;

  }
  printf("\nAlive Girl = %d\n",start->data);

   }



[algogeeks] Re: spoj

2012-02-16 Thread pavan
yeah the results are correct for the given inputs

On Feb 16, 1:03 am, atul anand  wrote:
> if i have understood the problem correctly...
> you please confirm the answers i am getting for the given inputs:-
>                           result
> 1) 1 2 3 4 5            4
> 2) 1 2 3 4 5 6         5
> 3) 1 2 3 4 5 6 7      4
> 4) 1 2 3 4 5 6 7 8   8
>
> On Wed, Feb 15, 2012 at 11:38 PM, Dheeraj Sharma <
>
> dheerajsharma1...@gmail.com> wrote:
> > yeah..we need to calculate some formula
>
> > On Wed, Feb 15, 2012 at 10:21 PM, pavan  wrote:
>
> >> @Utkarsh: yeah it is josephsus problem with a slight change.using
> >> a linked list will give u TLE i guess.
>
> >> On Feb 14, 10:36 pm, vickywiz  wrote:
> >> > in 1 2 3 4 5 6...o/p "ll b 5
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/algogeeks?hl=en.
>
> > --
> > *Dheeraj Sharma*
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from 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] Re: spoj

2012-02-15 Thread atul anand
if i have understood the problem correctly...
you please confirm the answers i am getting for the given inputs:-
  result
1) 1 2 3 4 54
2) 1 2 3 4 5 6 5
3) 1 2 3 4 5 6 7  4
4) 1 2 3 4 5 6 7 8   8

On Wed, Feb 15, 2012 at 11:38 PM, Dheeraj Sharma <
dheerajsharma1...@gmail.com> wrote:

> yeah..we need to calculate some formula
>
>
> On Wed, Feb 15, 2012 at 10:21 PM, pavan  wrote:
>
>> @Utkarsh: yeah it is josephsus problem with a slight change.using
>> a linked list will give u TLE i guess.
>>
>>
>> On Feb 14, 10:36 pm, vickywiz  wrote:
>> > in 1 2 3 4 5 6...o/p "ll b 5
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> *Dheeraj Sharma*
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Re: spoj

2012-02-15 Thread Dheeraj Sharma
yeah..we need to calculate some formula

On Wed, Feb 15, 2012 at 10:21 PM, pavan  wrote:

> @Utkarsh: yeah it is josephsus problem with a slight change.using
> a linked list will give u TLE i guess.
>
>
> On Feb 14, 10:36 pm, vickywiz  wrote:
> > in 1 2 3 4 5 6...o/p "ll b 5
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
*Dheeraj Sharma*

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



[algogeeks] Re: spoj

2012-02-15 Thread pavan
@Utkarsh: yeah it is josephsus problem with a slight change.using
a linked list will give u TLE i guess.


On Feb 14, 10:36 pm, vickywiz  wrote:
> in 1 2 3 4 5 6...o/p "ll b 5

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

2012-02-05 Thread saurabh singh
http://www.spoj.pl/problems/ABCPATH/
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Sun, Feb 5, 2012 at 11:18 PM, WgpShashank wrote:

> @trinity tell the link of problem ?
>
>
>
> *Thanks
> Shashank Mani Narayan
> Computer Science & Engineering
> Birla Institute of Technology,Mesra
> ** Founder Cracking The Code Lab  "http://shashank7s.blogspot.com/"*
>
>  --
> 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/-/VhCj6Mr4ao0J.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] Re: Spoj ABCPATH

2012-02-05 Thread WgpShashank
@trinity tell the link of problem ?



*Thanks
Shashank Mani Narayan
Computer Science & Engineering 
Birla Institute of Technology,Mesra 
** Founder Cracking The Code Lab  "http://shashank7s.blogspot.com/"*

-- 
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/-/VhCj6Mr4ao0J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: SPOJ TLE

2011-12-20 Thread KK
Try wid BFS.. thats the only alternative i can think off!! I got acc
wid that!!

On Dec 6, 12:29 pm, "varma C.S.P"  wrote:
> 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()
> {
>     int cases;
>     scanf("%d", &cases);
>     for(int i=1; i<=cases; i++)
>     {
>             scanf("%d %d", &bugs, &rel);
>             memset(g, 0x00, sizeof g);
>             int relq = rel;
>             while(relq--)
>             {
>                 scanf("%d %d", &v1, &v2);
>                 g[v1][++g[v1][0]]=v2;
>                 g[v2][++g[v2][0]]=v1;
>             }
>             printf("Scenario #%d:\n", i);
>             if(dfs())
>             {
>                      printf("No suspicious bugs found!\n");
>             }
>             else
>             {
>                 printf("Suspicious bugs found!\n");
>             }
>     }
>     return 0;}
>
> int inline complement(int n)
> {
>     if(n==1)
>             return 2;
>     if(n==2)
>             return 1;
>
> }
>
> bool inline dfs() //iterative DFS
> {
>     int node, no, in;
>     memset(color, 0x00, (bugs+1)*sizeof(int));
>     stack[0]=0;
>     for(int it = 1; it<=bugs; it++)
>     {
>         if(color[(it)]==0 && g[(it)][0]!=0)
>         {
>             stack[++stack[0]]=(it);
>             color[(it)] = 1;
>             while(stack[0] && (rel>0))     //if stack is not empty
>             {
>                 in = stack[stack[0]--];
>                 no = g[in][0];
>                 for(int j=1; j<=no; j++)
>                 {
>                     node = g[in][j];
>                     if(color[node]!=0)
>                     {
>                         if(color[node] == color[in])
>                         {
>                             return false;
>                         }
>                     }
>                     else
>                     {
>                         color[node] = complement(color[in]);
>                         stack[++stack[0]]=node;
>                         rel--;
>                     }
>                 }
>             }
>         }
>     }
>     return true;
>
> }
>
> Please help me.
>
> Ashok

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



[algogeeks] Re: SPOJ . 10186.PUCMM025

2011-12-15 Thread anubhav raj
hey ,i got the  bug and  got AC ALSO..there was
several bugs ...sry ,for silly dbt

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

2011-11-18 Thread Amol Sharma
hi all,
i implemented the same problem with bfs but i'm getting TLE.plz tell
how to reduce my running time
my code is as follows...

#include
#include
#include
#include
#include
#include

using namespace std;

int main()
{
int i,f,s,g,u,d;//f=no. of floors,s=start,g=goal,u=up,d=down
scanf("%d%d%d%d%d",&f,&s,&g,&u,&d);
if(s==g)
{
printf("0\n");
return 0;
}
vector< vector > v(f+1);//v[1] represents floors reachable
from 1st floor..till v[f]
//first task is to build the graph using no. of floor,up and down
for(i=1;i<=f;i++)
{
if( (i+u)<=f )
v[i].push_back(i+u);
if( (i-d)>=1 )
v[i].push_back(i-d);
}
//graph created
//now apply bfs from start node and check if we can reach goal...if yes
then in how many steps..
queue q;
vector p(f+1,0);//visited flag
q.push(s);//s is the start vertex
p[s]=1;
vector::iterator it;
vector a(f+1,0);//array containing distances
a[s]=0;
while(!q.empty())
{
i=q.front();
//get tail element from the queue
q.pop();
for(it=v[i].begin();it!=v[i].end();it++)
{
if( *it==g )
{
printf("%d\n",a[i]+1);
return 0;
}
if(!p[*it])//we have not visited this vertex yet
{
a[*it]=a[i]+1;
p[*it]=1;
q.push(*it);
}
}
}
printf("use the stairs\n");
return 0;
}


--


Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad







On Thu, Nov 17, 2011 at 5:48 PM, Anshul AGARWAL
wrote:

> finally got AC,(using bfs)
> thanx DON for provide such nice test case
>
> *Anshul Agarwal
> Nit Allahabad
> Computer Science**
> *
>
>
> On Wed, Nov 16, 2011 at 8:14 PM, SAMMM  wrote:
>
>> U need to check for the case when (s==g) source and destination are
>> same  , I got stuck here , after handling this case I got accepted :)
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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] Re: spoj problem

2011-11-18 Thread Amol Sharma
don't bother got AC was doing lot of extra overhead
--


Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad
 






On Fri, Nov 18, 2011 at 1:53 PM, Amol Sharma  wrote:

> hi all,
> i implemented the same problem with bfs but i'm getting TLE.plz tell
> how to reduce my running time
> my code is as follows...
>
> #include
> #include
> #include
> #include
> #include
> #include
>
>
> using namespace std;
>
> int main()
> {
> int i,f,s,g,u,d;//f=no. of floors,s=start,g=goal,u=up,d=down
> scanf("%d%d%d%d%d",&f,&s,&g,&u,&d);
>
> if(s==g)
> {
> printf("0\n");
> return 0;
> }
> vector< vector > v(f+1);//v[1] represents floors reachable
> from 1st floor..till v[f]
> //first task is to build the graph using no. of floor,up and down
> for(i=1;i<=f;i++)
> {
> if( (i+u)<=f )
> v[i].push_back(i+u);
> if( (i-d)>=1 )
> v[i].push_back(i-d);
> }
> //graph created
> //now apply bfs from start node and check if we can reach goal...if
> yes then in how many steps..
> queue q;
> vector p(f+1,0);//visited flag
> q.push(s);//s is the start vertex
> p[s]=1;
> vector::iterator it;
> vector a(f+1,0);//array containing distances
> a[s]=0;
> while(!q.empty())
> {
> i=q.front();
> //get tail element from the queue
> q.pop();
> for(it=v[i].begin();it!=v[i].end();it++)
> {
> if( *it==g )
> {
> printf("%d\n",a[i]+1);
> return 0;
> }
> if(!p[*it])//we have not visited this vertex yet
> {
> a[*it]=a[i]+1;
> p[*it]=1;
> q.push(*it);
>
> }
> }
> }
> printf("use the stairs\n");
> return 0;
> }
>
>
> --
>
>
> Amol Sharma
> Third Year Student
> Computer Science and Engineering
> MNNIT Allahabad
>  
> 
>
>
>
>
>
> On Thu, Nov 17, 2011 at 5:48 PM, Anshul AGARWAL <
> anshul.agarwa...@gmail.com> wrote:
>
>> finally got AC,(using bfs)
>> thanx DON for provide such nice test case
>>
>> *Anshul Agarwal
>> Nit Allahabad
>> Computer Science**
>> *
>>
>>
>> On Wed, Nov 16, 2011 at 8:14 PM, SAMMM  wrote:
>>
>>> U need to check for the case when (s==g) source and destination are
>>> same  , I got stuck here , after handling this case I got accepted :)
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from 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] Re: spoj problem

2011-11-17 Thread Anshul AGARWAL
finally got AC,(using bfs)
thanx DON for provide such nice test case

*Anshul Agarwal
Nit Allahabad
Computer Science**
*


On Wed, Nov 16, 2011 at 8:14 PM, SAMMM  wrote:

> U need to check for the case when (s==g) source and destination are
> same  , I got stuck here , after handling this case I got accepted :)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



[algogeeks] Re: spoj problem

2011-11-16 Thread SAMMM
U need to check for the case when (s==g) source and destination are
same  , I got stuck here , after handling this case I got accepted :)

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



[algogeeks] Re: spoj problem

2011-11-16 Thread Dave
It seems like a mathematical solution should be possible.

What we want to do is find m >= 0 and n <= 0 so that m * u + n * d = g
- s.

Pseudocode:

If (s + u > f and s - d < 1) or (f - d < g and 1 + u > g) then
return "use the stairs".
Use the Extended GCD algorithm (http://en.wikipedia.org/wiki/
Extended_Euclidean_algorithm#Iterative_method_2), to find gcd(u,d) and
x and y so that x*u + y*d = gcd(u,d).
If (g - s) is not divisible by gcd(u,d) then
Return "use the stairs".
Set m = x * (g - s) / gcd(u,d) and n = y * (g - s) / gcd(u,d)
While m >= d and n <= -u
Set m = m - d and n = n + u
While m < 0 or n > 0
Set m = m + d and n = n - u
Return m - n.

Dave

On Nov 14, 4:42 pm, Don  wrote:
> I solved this one with a breadth-first search.
> Don
>
> On Nov 14, 8:27 am, Anshul AGARWAL  wrote:
>
>
>
> > problem ishttp://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.



Re: [algogeeks] Re: spoj problem

2011-11-16 Thread Anshul AGARWAL
thanx Don.
i think my logic is not so good . now i try to make it using bfs .
*Anshul Agarwal
Nit Allahabad
Computer Science**
*


On Tue, Nov 15, 2011 at 5:36 PM, Don  wrote:

> This input
>
> 100 1 5 5 91
>
> Should output 20. Yours says "Take the stairs".
>
> 100 1 5 5 89
>
> Should output 76. Yours says "Take the stairs."
>
> Don
>
> On Nov 14, 8:27 am, Anshul AGARWAL  wrote:
> > problem ishttp://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.



Re: [algogeeks] Re: spoj problem

2011-11-16 Thread UTKARSH SRIVASTAV
hi don i have now implemented it with bfs but it's still giving wrong
answer can you please tell the test case
#include
int a[1000100][2];
int visited[1000100],i,q[1000100];
int main()
{
int f,s,g,u,d;
scanf("%d%d%d%d%d",&f,&s,&g,&u,&d);

for( i = 1 ; i <= f;i++)
{
if(i + u > f)
{
a[i][0] = i;
}
else
{
a[i][0] = i + u;
}
if( i - d < 1)
{
  a[i][1] = i;
}
else
{
a[i][1] = i - d;
}
visited[i] = 0;
}
/*for( i = 1  ;i <= f; i++)
{
printf("%d  %d  %d\n",i,a[i][0],a[i][1]);
}*/
int front  ,rear;
front = 0;
rear = 0;
q[0] = s;
visited[s] = 1;
front = 0;
int count = 0,flag = 0;
int p = 0;
while(front <= rear)
{
int h ;
/*for(  h = front ;h<= rear ;h++)
{
printf("%d ",q[h]);
}*/

if(!visited[a[q[front]][0]])
{
if(a[q[front]][0] == g)
{
flag = 1;
count++;
break;
}
p = 1;
q[++rear] = a[q[front]][0];
visited[a[q[front]][0]] = 1;
}
if(!visited[a[q[front]][1]])
{
if(a[q[front]][1] == g)
{
flag = 1;
count++;
break;
}
p = 1;
q[++rear] = a[q[front]][1];
visited[a[q[front]][1]] = 1;
}
if( p == 1)
count++;
p = 0;
front++;
/*printf("\n");
scanf("%d",&h);*/
}
if(flag == 0)
{
printf("use the stairs\n");
}
else
{
printf("%d\n",count);
}
return 0;
}


On Wed, Nov 16, 2011 at 4:06 AM, Don  wrote:

> This input
>
> 100 1 5 5 91
>
> Should output 20. Yours says "Take the stairs".
>
> 100 1 5 5 89
>
> Should output 76. Yours says "Take the stairs."
>
> Don
>
> On Nov 14, 8:27 am, Anshul AGARWAL  wrote:
> > problem ishttp://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 Allah

[algogeeks] Re: spoj problem

2011-11-15 Thread Don
This input

100 1 5 5 91

Should output 20. Yours says "Take the stairs".

100 1 5 5 89

Should output 76. Yours says "Take the stairs."

Don

On Nov 14, 8:27 am, Anshul AGARWAL  wrote:
> problem ishttp://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.



[algogeeks] Re: spoj problem

2011-11-15 Thread Don
I don't think that your solution assures that the elevator stays in
its bounds.
Don

On Nov 15, 12:49 pm, UTKARSH SRIVASTAV 
wrote:
> hi don please tell me where am i wrong in this maths in solving this
> question.
>
>      let x = number of times to press up button
> let y =  number of times to press down button
>   k = g -s
> so we have
>     u*x - d*y = k --->(1)
>     we have to minimize x + y
>     so from (1) x = (k+d*y)/u;
>     x + y = (k + d*y)/u + y
>     now if u analyze (k + dy ) should be integer
>     so (k + d* y) %u = 0
>     k%u + (d*y)%u = 0;
>     (dy)%u = u - (k%u)
>     dy = pu + (u - (k%u))
>     where p is any integer
>     y = pu/d +(u -(k%u))/d
>     so for y to be minimum
>     p = 0;
>     so y = (u - (k%u))/d;
>     if we know y we can get x and x + y
>
>     CORRECT ME IF I AM WRONG
>
>
>
> On Tue, Nov 15, 2011 at 4:12 AM, Don  wrote:
> > I solved this one with a breadth-first search.
> > Don
>
> > On Nov 14, 8:27 am, Anshul AGARWAL  wrote:
> > > problem ishttp://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.
>
> --
> *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] Re: spoj problem

2011-11-15 Thread UTKARSH SRIVASTAV
hi don please tell me where am i wrong in this maths in solving this
question.

 let x = number of times to press up button
let y =  number of times to press down button
  k = g -s
so we have
u*x - d*y = k --->(1)
we have to minimize x + y
so from (1) x = (k+d*y)/u;
x + y = (k + d*y)/u + y
now if u analyze (k + dy ) should be integer
so (k + d* y) %u = 0
k%u + (d*y)%u = 0;
(dy)%u = u - (k%u)
dy = pu + (u - (k%u))
where p is any integer
y = pu/d +(u -(k%u))/d
so for y to be minimum
p = 0;
so y = (u - (k%u))/d;
if we know y we can get x and x + y

CORRECT ME IF I AM WRONG

On Tue, Nov 15, 2011 at 4:12 AM, Don  wrote:

> I solved this one with a breadth-first search.
> Don
>
> On Nov 14, 8:27 am, Anshul AGARWAL  wrote:
> > problem ishttp://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.
>
>


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



[algogeeks] Re: spoj problem

2011-11-14 Thread Don
I solved this one with a breadth-first search.
Don

On Nov 14, 8:27 am, Anshul AGARWAL  wrote:
> problem ishttp://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.



Re: [algogeeks] Re: SPOJ PIGBANK Problem

2011-09-30 Thread manish patel
thanks man i got it .. :)

On Fri, Sep 30, 2011 at 12:17 AM, Don  wrote:

> I think that it will fail if the value of the coins can be more than
> 50001.
> Don
>
> On Sep 29, 12:35 pm, manish patel  wrote:
> > http://www.spoj.pl/problems/PIGBANK/
> >
> > please suggest some test case where it fails ...
> >
> > [code]
> > #include
> > main()
> > {int t=0,n,e,f,i,j;
> > int p[50002],w[10002];
> > scanf("%d",&t);
> > while(t--)
> > {scanf("%d %d",&e,&f);
> > scanf("%d",&n);
> > for(i=0;i > {scanf("%d %d",&p[i],&w[i]);
> > }
> > int min[f-e+2];
> > for(i=e;i<=f+2;i++)
> > {min[i-e]=50001;
> > }
> > min[0]=0;
> > for(i=e+1;i<=f;i++)
> > {for(j=0;j > {if(w[j]<=(i-e)&& min[i-e-w[j]]+p[j] < min[i-e])
> > min[i-e]=min[i-e-w[j]]+p[j];
> >
> > }
> > }
> > if(min[f-e]==50001||min[f-e]==0)
> > printf("This is impossible.\n");
> > else
> > printf("The minimum amount of money in the piggy-bank is
> > %d.\n",min[f-e]);
> > }
> > return 0;
> >
> > }
> >
> > [/code]
> >
> > --
> > With Regards
> >
> > Manish Patel
> > BTech
> > Computer Science And Engineering
> > National Institute of Technology -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.
>
>


-- 
With Regards

Manish Patel
BTech
Computer Science And Engineering
National Institute of Technology -Allahabad

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



[algogeeks] Re: SPOJ PIGBANK Problem

2011-09-29 Thread Don
I think that it will fail if the value of the coins can be more than
50001.
Don

On Sep 29, 12:35 pm, manish patel  wrote:
> http://www.spoj.pl/problems/PIGBANK/
>
> please suggest some test case where it fails ...
>
> [code]
> #include
> main()
> {    int t=0,n,e,f,i,j;
>     int p[50002],w[10002];
>     scanf("%d",&t);
>     while(t--)
>     {    scanf("%d %d",&e,&f);
>         scanf("%d",&n);
>         for(i=0;i         {    scanf("%d %d",&p[i],&w[i]);
>         }
>         int min[f-e+2];
>         for(i=e;i<=f+2;i++)
>         {    min[i-e]=50001;
>         }
>         min[0]=0;
>         for(i=e+1;i<=f;i++)
>         {    for(j=0;j             {    if(w[j]<=(i-e)&& min[i-e-w[j]]+p[j] < min[i-e])
>                     min[i-e]=min[i-e-w[j]]+p[j];
>
>             }
>         }
>         if(min[f-e]==50001||min[f-e]==0)
>         printf("This is impossible.\n");
>         else
>         printf("The minimum amount of money in the piggy-bank is
> %d.\n",min[f-e]);
>     }
>     return 0;
>
> }
>
> [/code]
>
> --
> With Regards
>
> Manish Patel
> BTech
> Computer Science And Engineering
> National Institute of Technology -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] Re: SPOJ problem

2011-09-17 Thread amrit harry
@dave +1

On Sat, Sep 17, 2011 at 8:10 PM, Dave  wrote:

> @Amrit: You only have 2 and 3 litre jars. You are trying to get 4
> litres into one of them. There is no 4 litre jar, nor any other vessel
> into which you can capture the 4 litres.
>
> Dave
>
> On Sep 17, 6:15 am, amrit harry  wrote:
> > http://www.spoj.pl/problems/POUR1/
> > hw the 2nd given test is correct.
> >
> > 2
> > 3
> > 4
> > first we fill 3 littre jar with water and put into 4 littre jar den
> > again fill 3 littre and pour it in 2 littre remaining water in jar is
> > 1 littre put it into 4 littre and we can measure 4 littre of water den
> > why answer is -1...?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
AMRIT

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



[algogeeks] Re: SPOJ problem

2011-09-17 Thread Dave
@Amrit: You only have 2 and 3 litre jars. You are trying to get 4
litres into one of them. There is no 4 litre jar, nor any other vessel
into which you can capture the 4 litres.

Dave

On Sep 17, 6:15 am, amrit harry  wrote:
> http://www.spoj.pl/problems/POUR1/
> hw the 2nd given test is correct.
>
> 2
> 3
> 4
> first we fill 3 littre jar with water and put into 4 littre jar den
> again fill 3 littre and pour it in 2 littre remaining water in jar is
> 1 littre put it into 4 littre and we can measure 4 littre of water den
> why answer is -1...?

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



Re: [algogeeks] Re: SPOJ ACODE

2011-08-28 Thread kartik sachan
THANKs amol piyush i got my mistake

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

2011-08-28 Thread Amol Sharma
I/P
30
105
1055
0

O/P
0
1
1

your code gives

1
1
1

(Copied from comments below the statement on Spoj )
--


Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad







On Sat, Aug 27, 2011 at 11:13 PM, Piyush Kapoor  wrote:

> There is nothing much particular to java,,
> Here is the code(simply copy pasted from the above one) in C::
>  int main(){
> char ar[100];
> int dp[1000];
> scanf("%s",ar);
> if(ar[l-1]!='0')
> dp[l-1]=1;
> for(int j=l-2;j>=0;j--)
> {
> int a=ar[j]-'0',b=ar[j+1]-'0';
> if(j==(l-2)  && (10*a+b)<=26)
> {
> if(a!=0)
> dp[j]=1+dp[j+1];
> }
> else if(j==(l-2) && (10*a+b)>26)
> dp[j]=dp[j+1];
> else if(j!=(l-2) && (10*a+b)<=26)
> {
> if(a!=0)
> dp[j]=dp[j+1]+dp[j+2];
> }
> else
> {
> dp[j]=dp[j+1];
> }
> }
> printf("%d\n",dp[0]);
> return 0;
>}
>
> --
> *Regards,*
> *Piyush Kapoor,*
> *2nd year,CSE
> IT-BHU*
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Re: SPOJ ACODE

2011-08-27 Thread Piyush Kapoor
There is nothing much particular to java,,
Here is the code(simply copy pasted from the above one) in C::
 int main(){
char ar[100];
int dp[1000];
scanf("%s",ar);
if(ar[l-1]!='0')
dp[l-1]=1;
for(int j=l-2;j>=0;j--)
{
int a=ar[j]-'0',b=ar[j+1]-'0';
if(j==(l-2)  && (10*a+b)<=26)
{
if(a!=0)
dp[j]=1+dp[j+1];
}
else if(j==(l-2) && (10*a+b)>26)
dp[j]=dp[j+1];
else if(j!=(l-2) && (10*a+b)<=26)
{
if(a!=0)
dp[j]=dp[j+1]+dp[j+2];
}
else
{
dp[j]=dp[j+1];
}
}
printf("%d\n",dp[0]);
return 0;
   }

-- 
*Regards,*
*Piyush Kapoor,*
*2nd year,CSE
IT-BHU*

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

2011-08-27 Thread kartik sachan
thanks piyush for replying but i don't have complier for java and i don't
know even java

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

2011-08-27 Thread Piyush Kapoor
You can check your answers on my AC code::
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String args[])throws Exception
{
BufferedReader in=new BufferedReader(new
InputStreamReader(System.in));
StringBuffer out=new StringBuffer("");
String s;
while(!(s=in.readLine()).equals("0"))
{
int l=s.length();
int dp[]=new int[l];char ar[];
ar=s.toCharArray();
if(ar[l-1]!='0')
dp[l-1]=1;
for(int j=l-2;j>=0;j--)
{
int a=ar[j]-'0',b=ar[j+1]-'0';
if(j==(l-2)  && (10*a+b)<=26)
{
if(a!=0)
dp[j]=1+dp[j+1];
}
else if(j==(l-2) && (10*a+b)>26)
dp[j]=dp[j+1];
else if(j!=(l-2) && (10*a+b)<=26)
{
if(a!=0)
dp[j]=dp[j+1]+dp[j+2];
}
else
{
dp[j]=dp[j+1];
}
}
out.append(dp[0]+"\n");
}
System.out.println(out);
}
}

-- 
*Regards,*
*Piyush Kapoor,*
*2nd year,CSE
IT-BHU*

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



[algogeeks] Re: SPOJ ACODE

2011-08-27 Thread kartik sachan
koyi to test cases de jisme mera code fail kare?

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

2011-08-24 Thread Aastha Rai
hey! the solution can be found by summation from 1 to n + 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] Re: spoj coin tossing

2011-08-24 Thread Piyush Kapoor
@keyan karthi
Can you explain a bit on how to use the markov chain to get the answer...

On Wed, Aug 24, 2011 at 11:42 PM, him  wrote:

> 1st one
> H->2^1+1
> HTHT->2^4+4
> TTHTHTHTHTHHTHTHTHTTHTHTT(33) -> 2^33+6(why)?
>
> do you see any connection?
>
> On Aug 24, 6:55 am, keyankarthi  wrote:
> > http://www.spoj.pl/problems/MAIN8_D/
> >
> > i tried solving this problem
> > any ideas...??
> > for second test case 'htht'
> > the states i considered are
> > 1 T  -  (1/2) * x+1
> > 2 HH - (1/4) * x+2
> > 3 HTT - (1/8) * x+3
> > 4 HTHH - (1/16) * x+4
> > 5 HTHT  - (1/16)(final state)
> >
> > x is the expected no of coins.
> > x= 1 + 2+3+4+5
> > gives 16x=15x+26
> > x=26.
> >
> > answer given is 20...
> > can any one explain 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.
>
>


-- 
*Regards,*
*Piyush Kapoor,*
*2nd year,CSE
IT-BHU*

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



[algogeeks] Re: spoj coin tossing

2011-08-24 Thread him
1st one
H->2^1+1
HTHT->2^4+4
TTHTHTHTHTHHTHTHTHTTHTHTT(33) -> 2^33+6(why)?

do you see any connection?

On Aug 24, 6:55 am, keyankarthi  wrote:
> http://www.spoj.pl/problems/MAIN8_D/
>
> i tried solving this problem
> any ideas...??
> for second test case 'htht'
> the states i considered are
> 1     T  -  (1/2) * x+1
> 2     HH - (1/4) * x+2
> 3     HTT - (1/8) * x+3
> 4     HTHH - (1/16) * x+4
> 5     HTHT  - (1/16)    (final state)
>
> x is the expected no of coins.
> x= 1 + 2+3+4+5
> gives 16x=15x+26
> x=26.
>
> answer given is 20...
> can any one explain this,

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



Re: [algogeeks] Re: SPOJ CENCRY

2011-08-10 Thread kartik sachan
thanks nitin got AC...:) silliy mistake

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

2011-08-10 Thread Nitin Nizhawan
inp:
3
eee

vfghjklwerf

out:
cjpvbhntzgm
aeiouaeiouae
eouaeioicou

On Wed, Aug 10, 2011 at 12:40 PM, Nitin Nizhawan
wrote:

> 3
> eee
> cjpvbhntzgm
> 
> aeiouaeiouae
> vfghjklwerf
> eouaeioicou
>
> On Wed, Aug 10, 2011 at 12:06 PM, kartik sachan 
> wrote:
>
>> any body tell the test cases??
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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] Re: SPOJ CENCRY

2011-08-10 Thread Nitin Nizhawan
3
eee
cjpvbhntzgm

aeiouaeiouae
vfghjklwerf
eouaeioicou

On Wed, Aug 10, 2011 at 12:06 PM, kartik sachan wrote:

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

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



[algogeeks] Re: SPOJ CENCRY

2011-08-09 Thread kartik sachan
any body tell the test cases??

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



[algogeeks] Re: SPOJ ABCD

2011-08-07 Thread amit karmakar
@amol
I got accepted using the similar approach. But i performed
backtracking. In each step of backtracking i chose the next option as
you done. So, there can be cases where this approach fails.

Runtime error may occur because,

>> while(count[k-'A'].second>=n||count[k-'A'].first==up[i]||count[k-'A'].first 
>> ==down[i-1])
>>   k++;
The above code segment assumes that you will get one of the ABCD to
fill the position. But in cases where none of these are possible you
will end up with out of bounds error.

On Aug 7, 1:23 am, Amol Sharma  wrote:
> i attempted a problem
>  http://www.spoj.pl/problems/ABCD/
>
> my logic is scan the input string and record the count of A, B, C, D in
> array of size 4
>
> now sort the count array
>
> in the output array at first position put an element from count array
> whose count is less than n and not equal to element above them...
>
> then for other positions put element from the count array whose count is
> less(minimum) than n and they are not equal to previous element and element
> above them...
>
> it is working fine for most of the cases but i was able to figure out the
> cases where it failed
>
> input -   BCDBCD
> output - ABACAH   which is wrong it should be ABADAC or ADACAB.
>
> i am getting a run time error on submission
>
> Please help me in correcting my logic to reach to the correct solution.
> My Code is as follows
>
> -
>
> #include
> #include
> #include
> #include
> #include
>
> using namespace std;
>
> //problem four colours ABCD
>
> bool myfunc(pair i,pair j)
> {
> return (i.second < j.second);
>
> }
>
> int main()
> {
>     int n;
>     scanf("%d",&n);
>     //now up and down array should have 2n colours and each colour should be
> present n times
>         vector< pair > count(4);
>
>         //count array will store the frequency of each colour
>         int i,j;
>         char k,down[10];
>         string up;
>         count[0].first='A';
>         count[1].first='B';
>         count[2].first='C';
>         count[3].first='D';
>         count[0].second=count[1].second=count[2].second=count[3].second=0;
>         cin >> up;
>         //string up is scanned
>         //get the count of each colour in up string
>         for(i=0;i<2*n;i++)
>         {
>             count[up[i]-'A'].second+=1;
>         }
>      /*   for(j=0;j<4;j++)
>                      printf("%c\t%d\t",count[j].first,count[j].second);
>         printf("\n");*/
>         //now scan the above string and construct the down string together
>         for(i=0;i<2*n;i++)
>         {
>             sort(count.begin(),count.end(),myfunc);
>             /*for(j=0;j<4;j++)
>                      printf("%c\t%d\t",count[j].first,count[j].second);
>             printf("\n");*/
>             if(i==0)
>             {
>                 //this is the case when we have first element to fill
>                 k='A';
>                 while(count[k-'A'].second>=n||count[k-'A'].first==up[i])
>                     k++;
>                 down[i]=count[k-'A'].first;
>                 count[k-'A'].second+=1;
>             }
>             else
>             {
>                 k='A';
>
> while(count[k-'A'].second>=n||count[k-'A'].first==up[i]||count[k-'A'].first 
> ==down[i-1])
>                     k++;
>                 down[i]=count[k-'A'].first;
>                 count[k-'A'].second+=1;
>             }
>             /*printf("Hi\n");
>             for(j=0;j<4;j++)
>                      printf("%c\t%d\t",count[j].first,count[j].second);
>             printf("\n");*/
>         }
>        down[2*n]='\0';
>         cout<     //system("pause");
> return 0;
>
> }
>
> --
>
> Amol Sharma
> Third Year Student
> Computer Science and Engineering
> 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] Re: SPOJ LITE

2011-08-01 Thread Amol Sharma
can u explain or some useful link ??
--


Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad




On Mon, Aug 1, 2011 at 10:16 PM, Rohan Kalra wrote:

> Use lazy propagation.
>
> --
> 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/-/3YMdS5bKx_sJ.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] Re: SPOJ LITE

2011-08-01 Thread Rohan Kalra
Use lazy propagation.

-- 
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/-/3YMdS5bKx_sJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Re: SPOJ

2011-07-25 Thread shady
I request you all to concentrate on algorithms and not the bits of coding.
When your code is giving WA on any judge then please first state your
algorithm. Take feedback from fellow users. If it is wrong then try
debugging it your self, corner cases, and even after spending 3-4 days if
you are still getting WA then give your code, which should be well
documented.

Thanks.

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



Re: [algogeeks] Re: SPOJ

2011-07-25 Thread shady
thanks sunny.

KK this is not your playground. People from all over the world are in this
group. These are the people who have left companies like MS because of their
love for algorithms discuss ideas. Only way you learn debugging is by
practice. Once it took me 5 continuous hours to debug one bug in MATLAB.
That was a missing ':'

@moderators KK banned for 1 week, don't unban him

On Mon, Jul 25, 2011 at 8:14 PM, sunny agrawal wrote:

> First Thing is that i will support Shady's point.
> Please Post the question and the idea u r trying to solve the
> questionnot the complete Code so that algorithm can be discussed here
> and then u can identify your mistake.
>
> because this happens most of the time when someone posts code, most of the
> peoples won't be going to read your code and result is delayed response to
> your post.
>
>
> On Mon, Jul 25, 2011 at 7:34 PM, KK  wrote:
>
>> @piyush:
>> even if r = di and c = dj then whats the 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.
>>
>>
>
>
> --
> Sunny Aggrawal
> B-Tech IV year,CSI
> Indian Institute Of Technology,Roorkee
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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

2011-07-25 Thread sunny agrawal
First Thing is that i will support Shady's point.
Please Post the question and the idea u r trying to solve the
questionnot the complete Code so that algorithm can be discussed here
and then u can identify your mistake.

because this happens most of the time when someone posts code, most of the
peoples won't be going to read your code and result is delayed response to
your post.

On Mon, Jul 25, 2011 at 7:34 PM, KK  wrote:

> @piyush:
> even if r = di and c = dj then whats the 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.
>
>


-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

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



[algogeeks] Re: SPOJ

2011-07-25 Thread KK
@piyush:
even if r = di and c = dj then whats the 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.



[algogeeks] Re: SPOJ

2011-07-25 Thread KK
@shady: if ur not interested dont post ur comment, but let others do
it..
@viswamath: WA

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



[algogeeks] Re: SPOJ Problem DP

2011-07-02 Thread shady
any spojjer in the group ? if you want i can post my solution with
djikstra's :P ?

Shady

On Sat, Jul 2, 2011 at 10:31 AM, shady  wrote:

> Hi,
> I am solving this http://www.spoj.pl/problems/DP/ problem using Djikstra's
> algorithm. What is the dynamic programming solution to this ?
>
> PS : Don't post the code, but the states of dp.
>
> Thanks.
>
> Shady
>

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



[algogeeks] Re: SPOJ GPA1

2011-07-01 Thread cegprakash
its ok :) but i'm not sir n all.. i'm a student :P

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

2011-07-01 Thread kartik sachan
@thanks ceg sirfinally got acceptedur test
case worked..silly mistake...>=  error

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



[algogeeks] Re: SPOJ GPA1

2011-06-30 Thread cegprakash
@kartik sachan:

I just compared your output file with the output file

for this test case

5 1 2 3 4 5
19 ab ab 100 50
20 20 20 75 75
10 0 ab 88 0
13 12 15.5 88 99
12 7 9 66 66
11 ab ab 99 100

your code outputs "FAILED, 4.35" but actually he's "PASSED, 7.20"

I think you are assuming he's fail if he bunks 2 internal assessments.

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

2011-06-29 Thread kartik sachan
@sunny atof(ab) is giving me as zero.so it will not affect
the calculation i think so...

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

2011-06-29 Thread sunny agrawal
hey how r u dealing with absent cases.
for each case u r directly converting string to float
but for absent u will call atof() for "ab" and compare it.

On Wed, Jun 29, 2011 at 11:02 PM, kartik sachan wrote:

> any one plzz reply
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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 IV year,CSI
Indian Institute Of Technology,Roorkee

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



[algogeeks] Re: SPOJ GPA1

2011-06-29 Thread kartik sachan
any one plzz reply

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

2011-06-28 Thread D!leep Gupta
@vaibhav :acc. to u Its giving 9 for "BGBBGGGBBBGBGB" bt it should be 8
how?
my code:
#include
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int i=0,s=0,count=0,c=0,flag=1;
char a[15],ch;
scanf("%s",a);
while(a[i]!='\0')
{   if(flag) while(a[i]=='B') {i++; flag=0;}  //except heading
'B'
while(a[i]=='G')
{count++; i++;}
s+=(count-1);
count=0;
while(a[i]=='B')
{c++; i++;}
s+=c;
c=0;

}
printf("%d\n",s);
}
return 0;
}

On Tue, Jun 28, 2011 at 12:50 AM, vaibhav agarwal <
vibhu.bitspil...@gmail.com> wrote:

> @kartik also consider the case of  GB the answer is 1 BG. ie
> trailing G's left.
> BGB leading B's left hence only one G followed by B therefore only one
> iteration.
>
> try out some cases u will find hw it wrks.
>
>
> On Tue, Jun 28, 2011 at 12:42 AM, vaibhav agarwal <
> vibhu.bitspil...@gmail.com> wrote:
>
>> @kartik
>>
>> yup frgt to mention the last case 1 followed by zero's in that case number
>> of iterations is the no. of trailing zeroes.
>> GBGBBB
>> will have four iterations
>> 101000 = 1(one zero b/w two ones) + 3(last 1 followed by 3 zero's)
>>
>> BGBGBB,BBGBGB,BBBGBG,GG
>>
>> well logic is how hw mny jump of 1's u need to do to get it to the end of
>> the sequence.
>> GBG requires 1 iteration ie BGG
>>
>>
>> On Mon, Jun 27, 2011 at 11:27 PM, kartik sachan 
>> wrote:
>>
>>> HEY DUDE I AM NOT GETTING UR LOGIC AT ALL I THINK HOW U WILL SATISFY THIS
>>> CASE GBGBBB
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from 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.
>



-- 
Dileep Kumar
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@googlegroups.com.
To unsubscribe from 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] Re: spoj shlights

2011-06-28 Thread kartik sachan
if u want code then mail me.

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



Re: [algogeeks] Re: spoj shlights

2011-06-28 Thread kartik sachan
just count the how many shift u required to shift last G from (right to
left)...to reach it postion.but be carefull as there
are the situation and steps in which last G will not move ex
GGGBGBGBBBB

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

2011-06-28 Thread ankit sambyal
@kartik : What is ur 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] Re: spoj shlights

2011-06-28 Thread ankit sambyal
@vaibhav agarwal: case 3 of urs gives ans 6 according to ur algo, but
the correct ans is 5

also the following test case also gives wrong ans with ur algo :
GBBGBBBB
Ur algo give -   9
Correct ans--   7

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

2011-06-28 Thread kartik sachan
http://www.spoj.pl/problems/SHLIGHTS/

this is the link

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

2011-06-28 Thread sagar pareek
Well can anyone pls re post the problem?

On Tue, Jun 28, 2011 at 3:20 PM, kartik sachan wrote:

> @ vaibhav i have submitted my concept in spoj and it got AC in .02 sec
>
> i am saying for u have to play with index of EITHER of G or B
>
> now u have to think logic by taking two or more exmaple and shift it
> in...do it in paperu will see some pattern
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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
SAGAR PAREEK
COMPUTER SCIENCE AND 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@googlegroups.com.
To unsubscribe from 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] Re: spoj shlights

2011-06-28 Thread kartik sachan
@ vaibhav i have submitted my concept in spoj and it got AC in .02 sec

i am saying for u have to play with index of EITHER of G or B

now u have to think logic by taking two or more exmaple and shift it
in...do it in paperu will see some pattern

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

2011-06-28 Thread vaibhav agarwal
@kartik it's wrng got it

On 6/28/11, vaibhav agarwal  wrote:
> @kartik the sequence 101001100011000101101101011 can be done
> in 25 iterations
> whts urs?
>
> On 6/28/11, kartik sachan  wrote:
>> anonymous u have to play with the index no of either G or
>> B...and see how many shift it will require to reach it
>> original
>> postion then max will be the ans..
>>
>>
>> well GBGBBB
>> if we start from right to left then G=3 and G=5
>> first G have reach to 0 pos and second G have to reach to 1 pos
>> for first it require 2 steps and second require 4 steps
>>
>> so final ans will 4
>>
>>
>> u have to think logic for this case too when like this come
>> GGGGGBGBG
>>
>> here G come one after other there is one trick for this.u
>> have
>> to thnik and implement the code is 6 to 8 line only
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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] Re: spoj shlights

2011-06-28 Thread vaibhav agarwal
@kartik the sequence 101001100011000101101101011 can be done
in 25 iterations
whts urs?

On 6/28/11, kartik sachan  wrote:
> anonymous u have to play with the index no of either G or
> B...and see how many shift it will require to reach it original
> postion then max will be the ans..
>
>
> well GBGBBB
> if we start from right to left then G=3 and G=5
> first G have reach to 0 pos and second G have to reach to 1 pos
> for first it require 2 steps and second require 4 steps
>
> so final ans will 4
>
>
> u have to think logic for this case too when like this come
> GGGGGBGBG
>
> here G come one after other there is one trick for this.u have
> to thnik and implement the code is 6 to 8 line only
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Re: spoj shlights

2011-06-28 Thread kartik sachan
anonymous u have to play with the index no of either G or
B...and see how many shift it will require to reach it original
postion then max will be the ans..


well GBGBBB
if we start from right to left then G=3 and G=5
first G have reach to 0 pos and second G have to reach to 1 pos
for first it require 2 steps and second require 4 steps

so final ans will 4


u have to think logic for this case too when like this come
GGGGGBGBG

here G come one after other there is one trick for this.u have
to thnik and implement the code is 6 to 8 line only

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



[algogeeks] Re: spoj shlights

2011-06-28 Thread anonymous procrastination
@Kartik

Please tell me what logic you're following.

@varun

This strategy failed. I tried submitting.

GBGBBGGBBBGGBBBGBGGBGGBGBGG
101001100011000101101101011

You can try the above case.

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

2011-06-28 Thread vaibhav agarwal
@kartik well i hv written before trailing G's can be left in calculation
so it works fr GG.


On 6/28/11, kartik sachan  wrote:
> @VAIBHAV.ur logic fails in many
> cases...like G
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Re: spoj shlights

2011-06-27 Thread kartik sachan
@VAIBHAV.ur logic fails in many
cases...like G

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

2011-06-27 Thread kartik sachan
GOT AC IN .02 SEC  .:)))

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

2011-06-27 Thread vaibhav agarwal
@kartik also consider the case of  GB the answer is 1 BG. ie
trailing G's left.
BGB leading B's left hence only one G followed by B therefore only one
iteration.

try out some cases u will find hw it wrks.

On Tue, Jun 28, 2011 at 12:42 AM, vaibhav agarwal <
vibhu.bitspil...@gmail.com> wrote:

> @kartik
>
> yup frgt to mention the last case 1 followed by zero's in that case number
> of iterations is the no. of trailing zeroes.
> GBGBBB
> will have four iterations
> 101000 = 1(one zero b/w two ones) + 3(last 1 followed by 3 zero's)
>
> BGBGBB,BBGBGB,BBBGBG,GG
>
> well logic is how hw mny jump of 1's u need to do to get it to the end of
> the sequence.
> GBG requires 1 iteration ie BGG
>
>
> On Mon, Jun 27, 2011 at 11:27 PM, kartik sachan 
> wrote:
>
>> HEY DUDE I AM NOT GETTING UR LOGIC AT ALL I THINK HOW U WILL SATISFY THIS
>> CASE GBGBBB
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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] Re: spoj shlights

2011-06-27 Thread vaibhav agarwal
@kartik

yup frgt to mention the last case 1 followed by zero's in that case number
of iterations is the no. of trailing zeroes.
GBGBBB
will have four iterations
101000 = 1(one zero b/w two ones) + 3(last 1 followed by 3 zero's)

BGBGBB,BBGBGB,BBBGBG,GG

well logic is how hw mny jump of 1's u need to do to get it to the end of
the sequence.
GBG requires 1 iteration ie BGG

On Mon, Jun 27, 2011 at 11:27 PM, kartik sachan wrote:

> HEY DUDE I AM NOT GETTING UR LOGIC AT ALL I THINK HOW U WILL SATISFY THIS
> CASE GBGBBB
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Re: spoj shlights

2011-06-27 Thread kartik sachan
HEY DUDE I AM NOT GETTING UR LOGIC AT ALL I THINK HOW U WILL SATISFY THIS
CASE GBGBBB

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

2011-06-27 Thread vaibhav agarwal
consider G as 1, B as 0
so actually its series of 1 and 0's

now consider any sequence GBGBBGGGBG will be represented as
1010011101

objective is to push all 1's at the right end.
all '10' pairs need to be swapped at the same time.
considering this take for ex 101
the number of swaps is equal to the number of zeroes b/w two consecutive 1's
if the number of zeroes turn out to be 0 that is we have series of 1's in
the sequence then the number of swaps is equal to length of the series of
1's -1 .
leading zeroes is nt a problem and hence can be left in calculation.
add all that is ur answer.

case 1:  11001
 will require 1(first two 1's are consecutive so 2 - 1 )+2(zeroes b/w two
consecutive 1's) = 3
 10101,01011,00111

case 2: 1001 only 2(two zeroes)
0101,0011

case 3: 111011001
   will require 2(3 consecutive 1's)+1(single zero between 3rd and 4th
'1')+1(2 consecutive 1's)+2(two zeroes b/w last two 1's) = 6
110110101,101101011,011010111,01010,00101,00011

it wrking f9 with this .
correct me if i am wrng.

On Mon, Jun 27, 2011 at 9:33 PM, harshit pahuja wrote:

> hint is :  go for counting  ,not for shifting   o(n).  :P
>
>
> On Mon, Jun 27, 2011 at 9:29 PM, pacific :-) wrote:
>
>> Can one of you provide some hints in solving this problem ?
>>
>>
>> On Sat, Jun 25, 2011 at 3:34 PM, kartik sachan 
>> wrote:
>>
>>> @jitendra that's what i am asking forwhat algo i should
>>> implement  to get process in 1 sec?
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from 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,
>> 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.
>>
>
>
>
> --
> HARSHIT PAHUJA
> 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] Re: spoj shlights

2011-06-27 Thread harshit pahuja
hint is :  go for counting  ,not for shifting   o(n).  :P

On Mon, Jun 27, 2011 at 9:29 PM, pacific :-)  wrote:

> Can one of you provide some hints in solving this problem ?
>
>
> On Sat, Jun 25, 2011 at 3:34 PM, kartik sachan wrote:
>
>> @jitendra that's what i am asking forwhat algo i should
>> implement  to get process in 1 sec?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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,
> 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.
>



-- 
HARSHIT PAHUJA
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] Re: spoj shlights

2011-06-27 Thread pacific :-)
Can one of you provide some hints in solving this problem ?

On Sat, Jun 25, 2011 at 3:34 PM, kartik sachan wrote:

> @jitendra that's what i am asking forwhat algo i should
> implement  to get process in 1 sec?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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,
chinna.

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



Re: [algogeeks] Re: spoj shlights

2011-06-25 Thread kartik sachan
@jitendra that's what i am asking forwhat algo i should
implement  to get process in 1 sec?

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



[algogeeks] Re: spoj shlights

2011-06-24 Thread anonymous procrastination
Hello,

Were you able to figure out the solution?

On Jun 23, 3:33 pm, Jitendra singh  wrote:
> @ kartik sachan
> Problem with this code is this-
> All GB pairs should be process in one time period
>
> On 6/23/11, kartik sachan  wrote:
>
>
>
> > QUESTION LINK IShttp://www.spoj.pl/problems/SHLIGHTS/
>
> > MY CODE IS GIVEN BELOW
> > ITS IS GIVING TLEPLZZ HELP ME OUT
>
> > # include
> > # include
> > int main()
> > {
>
> > int t;
> > char a[17];
> > scanf("%d",&t);
> > int i,j,k;
>
> > while(t--)
> >     {
> >         int count=0;
> >         int flag=0,flag1=0;
>
> >         scanf("%s",a);
> >         while(1)
> >         {
>
> >             for(i=0;a[i]!='\0';i++)
> >                     if(a[i]=='G'&&a[i+1]=='B')
> >                         {a[i]='B';a[i+1]='G';i=i+1;flag1=1;}
> >             if(flag1==1)
> >             {count++;flag1=0;}
> >             if(count <=flag)
> >             break;
> >             flag=count;
> >         }
> >     printf("%d\n",count);
> >     }
> > return 0;
> > }
>
> > PLZZ HELP ME OUT OR SUGGEST ANY OTHER LOGIC IF IT  HAS SOME MISTAKES
>
> > --
>
> > *WITH REGARDS,*
> > *
> > *
> > *KARTIK SACHAN*
>
> > *B.TECH 2ND YEAR*
> > *COMPUTER SCIENCE AND 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@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
>
> - Show quoted text -

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



[algogeeks] Re: spoj problem chairs

2011-06-22 Thread VIHARRI
@saurabh : The answer suggested by you is for "not all together"...

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

2011-06-21 Thread keyan karthi
dp(int chair,int person,bool previous)
   if(previous)
 dp(chair-1,person,0)
else
  dp(chair-1,person-1,1)+dp(chair-1,person,0)

with basic conditions as it is a circle.. if person is placed in first
chair u cant place a person in last chair



On Tue, Jun 21, 2011 at 7:38 PM, shady  wrote:

> what will be the dynamic programming solution to the above problem ? can
> anyone explain the states of the dp ?
>
>
> On Mon, Jun 20, 2011 at 6:53 PM, oppilas . wrote:
>
>> I think you have not read the question carefully. Please read it again and
>> try to ans for small values of n,k first.
>> for k=1, answer will be always 1.
>>
>>
>> On Mon, Jun 20, 2011 at 6:31 PM, saurabh singh wrote:
>>
>>> O.K can anyone suggest the combinatorial solution.I thought it this way-
>>> Assume k chairs as one chair.Now no. of ways arranging these chairs would
>>> be ((n-k+1)-1)! and the number of ways of arranging the k chairs would be
>>> k!.
>>> So the no. of ways of arranging the chairs so that they are always
>>> together becomes..(n-1)!-(n-k)!*(k)!?
>>> Where was I wrong in the approach?Please correct me,
>>>
>>>
>>> On Mon, Jun 20, 2011 at 5:36 PM, RITESH SRIVASTAV <
>>> riteshkumar...@gmail.com> wrote:
>>>
 @Saurabh
 Your formula is incorrect.
 for input : 5 2
 the answer should be 5 but your program gives 12 as output.

 On Jun 19, 11:35 pm, abc abc  wrote:
 > @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.


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

2011-06-21 Thread shady
what will be the dynamic programming solution to the above problem ? can
anyone explain the states of the dp ?

On Mon, Jun 20, 2011 at 6:53 PM, oppilas . wrote:

> I think you have not read the question carefully. Please read it again and
> try to ans for small values of n,k first.
> for k=1, answer will be always 1.
>
>
> On Mon, Jun 20, 2011 at 6:31 PM, saurabh singh wrote:
>
>> O.K can anyone suggest the combinatorial solution.I thought it this way-
>> Assume k chairs as one chair.Now no. of ways arranging these chairs would
>> be ((n-k+1)-1)! and the number of ways of arranging the k chairs would be
>> k!.
>> So the no. of ways of arranging the chairs so that they are always
>> together becomes..(n-1)!-(n-k)!*(k)!?
>> Where was I wrong in the approach?Please correct me,
>>
>>
>> On Mon, Jun 20, 2011 at 5:36 PM, RITESH SRIVASTAV <
>> riteshkumar...@gmail.com> wrote:
>>
>>> @Saurabh
>>> Your formula is incorrect.
>>> for input : 5 2
>>> the answer should be 5 but your program gives 12 as output.
>>>
>>> On Jun 19, 11:35 pm, abc abc  wrote:
>>> > @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.
>>>
>>>
>>
>>
>> --
>> 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.
>

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

2011-06-20 Thread oppilas .
I think you have not read the question carefully. Please read it again and
try to ans for small values of n,k first.
for k=1, answer will be always 1.

On Mon, Jun 20, 2011 at 6:31 PM, saurabh singh  wrote:

> O.K can anyone suggest the combinatorial solution.I thought it this way-
> Assume k chairs as one chair.Now no. of ways arranging these chairs would
> be ((n-k+1)-1)! and the number of ways of arranging the k chairs would be
> k!.
> So the no. of ways of arranging the chairs so that they are always together
> becomes..(n-1)!-(n-k)!*(k)!?
> Where was I wrong in the approach?Please correct me,
>
>
> On Mon, Jun 20, 2011 at 5:36 PM, RITESH SRIVASTAV <
> riteshkumar...@gmail.com> wrote:
>
>> @Saurabh
>> Your formula is incorrect.
>> for input : 5 2
>> the answer should be 5 but your program gives 12 as output.
>>
>> On Jun 19, 11:35 pm, abc abc  wrote:
>> > @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.
>>
>>
>
>
> --
> 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] Re: spoj problem chairs

2011-06-20 Thread saurabh singh
O.K can anyone suggest the combinatorial solution.I thought it this way-
Assume k chairs as one chair.Now no. of ways arranging these chairs would be
((n-k+1)-1)! and the number of ways of arranging the k chairs would be k!.
So the no. of ways of arranging the chairs so that they are always together
becomes..(n-1)!-(n-k)!*(k)!?
Where was I wrong in the approach?Please correct me,

On Mon, Jun 20, 2011 at 5:36 PM, RITESH SRIVASTAV
wrote:

> @Saurabh
> Your formula is incorrect.
> for input : 5 2
> the answer should be 5 but your program gives 12 as output.
>
> On Jun 19, 11:35 pm, abc abc  wrote:
> > @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.
>
>


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



[algogeeks] Re: spoj problem chairs

2011-06-20 Thread RITESH SRIVASTAV
@Saurabh
Your formula is incorrect.
for input : 5 2
the answer should be 5 but your program gives 12 as output.

On Jun 19, 11:35 pm, abc abc  wrote:
> @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] Re: spoj NKTM

2011-06-15 Thread kartik sachan
without priority queue its .08 and with priority queue its .0.00

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

2011-06-15 Thread sunny agrawal
0.00 with priority_queue stl for me :)

On Thu, Jun 16, 2011 at 10:55 AM, Kunal Yadav wrote:

> Whats ur running time. Mine is 0.05 without using priority queque.
>
>
> On Wed, Jun 15, 2011 at 8:24 PM, kartik sachan wrote:
>
>> ya dude finally i applied that algo only
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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
> Kunal Yadav
> (http://algoritmus.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.
>



-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

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



Re: [algogeeks] Re: spoj NKTM

2011-06-15 Thread Kunal Yadav
Whats ur running time. Mine is 0.05 without using priority queque.

On Wed, Jun 15, 2011 at 8:24 PM, kartik sachan wrote:

> ya dude finally i applied that algo only
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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
Kunal Yadav
(http://algoritmus.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] Re: spoj NKTM

2011-06-15 Thread kartik sachan
ya dude finally i applied that algo only

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



[algogeeks] Re: spoj NKTM

2011-06-15 Thread KK
This q increased my score by directly 3 points... and thats a huge
one.. :D
@ kartik - Do it by priorty queue for better efficiency..

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



[algogeeks] Re: spoj NKTM

2011-06-14 Thread kartik sachan
case like
5
1 2 3 45
got worng ans

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



[algogeeks] Re: spoj NKTM

2011-06-14 Thread kartik sachan
got AC silliy mistake i am sorting array only one time..

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

2011-06-11 Thread Radhika Renganathan
im sorry .. y wrote:
> yea.. now got ac.. :) mistake was k==y is also possible but x got WA .. thank u :)
>
> On Sat, Jun 11, 2011 at 2:39 PM, keyan karthi
> wrote:
>
>> k=query(x,y-1)
>> if(k==x)
>> count++
>> with this change ur code ACs :)
>>
>>
>> On Sat, Jun 11, 2011 at 1:24 PM, Radhika Renganathan <
>> radi.coo...@gmail.com> wrote:
>>
>>> i did the same prob wit range maximum query.. but im repeatedly
>>> getting wrong answer.. im stuck with this prob for a long time.. pls
>>> help..
>>>
>>> my code:
>>>
>>> #include
>>> using namespace std;
>>> #include
>>> #include
>>> int A[50010];
>>> int M[999];
>>> void initialize(int node, int b, int e)
>>> {
>>>  if (b == e)
>>>  M[node] = b;
>>>  else
>>>   {
>>>  initialize(2 * node, b, (b + e) / 2);
>>>  initialize(2 * node + 1, (b + e) / 2 + 1,e);
>>>  if (A[M[2 * node]] >= A[M[2 * node + 1]])
>>>  M[node] = M[2 * node];
>>>  else
>>>  M[node] = M[2 * node + 1];
>>>  }
>>> }
>>> int query(int node, int b, int e, int i, int j)
>>> {
>>>  int p1, p2;
>>>  if (i > e || j < b)
>>>  return -;
>>>  if (b >= i && e <= j)
>>>  return M[node];
>>>  p1 = query(2 * node, b, (b + e) / 2,i, j);
>>>  p2 = query(2 * node + 1, (b + e) / 2 + 1, e, i, j);
>>>  if (p1 == -)
>>>  return p2;
>>>  if (p2 == -)
>>>  return p1;
>>>  if (A[p1] >= A[p2])
>>>  return p1;
>>>  return p2;
>>>
>>> }
>>>
>>> int main()
>>> {
>>>  int n,i,t,j,count=0,k,size;
>>>
>>>  scanf("%d%d",&n,&t);
>>>
>>>for (i=1;i<=n;i++)
>>>scanf("%d",&A[i]);
>>>
>>>  initialize(1,1,n);
>>>  for(i=0;i>>  {
>>>int x,y;
>>>scanf("%d%d",&x,&y);
>>>k=query(1,1,n,x,y);
>>>if(!(x>>count++;
>>>  }
>>>  printf("%d",count);
>>> return 0;
>>> }
>>>
>>>
>>> On 6/11/11, KK  wrote:
>>> > Search Topcoder Tutorial Range Minimum Query @ Google...
>>> > By few intuitive changes u can implement Range Maximum Query as
>>> > well...
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups
>>> > "Algorithm Geeks" group.
>>> > To post to this group, send email to algogeeks@googlegroups.com.
>>> > To unsubscribe from this group, send email to
>>> > algogeeks+unsubscr...@googlegroups.com.
>>> > For more options, visit this group at
>>> > http://groups.google.com/group/algogeeks?hl=en.
>>> >
>>> >
>>>
>>>
>>> --
>>>  radhika .. :)
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from 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.
>>
>
>
>
> --
>  radhika .. :)
>


-- 
 radhika .. :)

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

2011-06-11 Thread Radhika Renganathan
yea.. now got ac.. :) mistake was k==y is also possible but xwrote:

> k=query(x,y-1)
> if(k==x)
> count++
> with this change ur code ACs :)
>
>
> On Sat, Jun 11, 2011 at 1:24 PM, Radhika Renganathan <
> radi.coo...@gmail.com> wrote:
>
>> i did the same prob wit range maximum query.. but im repeatedly
>> getting wrong answer.. im stuck with this prob for a long time.. pls
>> help..
>>
>> my code:
>>
>> #include
>> using namespace std;
>> #include
>> #include
>> int A[50010];
>> int M[999];
>> void initialize(int node, int b, int e)
>> {
>>  if (b == e)
>>  M[node] = b;
>>  else
>>   {
>>  initialize(2 * node, b, (b + e) / 2);
>>  initialize(2 * node + 1, (b + e) / 2 + 1,e);
>>  if (A[M[2 * node]] >= A[M[2 * node + 1]])
>>  M[node] = M[2 * node];
>>  else
>>  M[node] = M[2 * node + 1];
>>  }
>> }
>> int query(int node, int b, int e, int i, int j)
>> {
>>  int p1, p2;
>>  if (i > e || j < b)
>>  return -;
>>  if (b >= i && e <= j)
>>  return M[node];
>>  p1 = query(2 * node, b, (b + e) / 2,i, j);
>>  p2 = query(2 * node + 1, (b + e) / 2 + 1, e, i, j);
>>  if (p1 == -)
>>  return p2;
>>  if (p2 == -)
>>  return p1;
>>  if (A[p1] >= A[p2])
>>  return p1;
>>  return p2;
>>
>> }
>>
>> int main()
>> {
>>  int n,i,t,j,count=0,k,size;
>>
>>  scanf("%d%d",&n,&t);
>>
>>for (i=1;i<=n;i++)
>>scanf("%d",&A[i]);
>>
>>  initialize(1,1,n);
>>  for(i=0;i>  {
>>int x,y;
>>scanf("%d%d",&x,&y);
>>k=query(1,1,n,x,y);
>>if(!(x>count++;
>>  }
>>  printf("%d",count);
>> return 0;
>> }
>>
>>
>> On 6/11/11, KK  wrote:
>> > Search Topcoder Tutorial Range Minimum Query @ Google...
>> > By few intuitive changes u can implement Range Maximum Query as well...
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Algorithm Geeks" group.
>> > To post to this group, send email to algogeeks@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > algogeeks+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/algogeeks?hl=en.
>> >
>> >
>>
>>
>> --
>>  radhika .. :)
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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.
>



-- 
 radhika .. :)

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