[algogeeks] acm problem : i need help

2007-05-16 Thread mirchi

hello people ,
i am facing a problem in submission of The Hamming Disteance 
problem. the output seems to be fine. but the program crashes in
between. the error says:

The instruction at 0x7c93426d referenced memory at 0x .
The memory could not be read .

and the acm feedback error says :

Your program has died with signal 11 (SIGSEGV). Meaning:

   Invalid memory reference

Before crash, it ran during 0.004 seconds.

the code is as below :

#includestdio.h
#includestdlib.h
void func (int k , int m , int r , int n , char *str , int count);
int main()
{
int i,count=0;
int noi,ij;
int r,n;
char *str;
scanf(%d,noi);
for(ij=0;ijnoi;ij++)
{
   scanf(%d %d,n,r);
   str=(char *)malloc(sizeof(char)*n);
   for(i=0;in;i++)
   {
str[i]='0';
   }
   str[n]=NULL;
   func(0,n-r,r,n,str,count);
}
return 0;
}
void func (int k , int m , int r , int n , char *str,int count)
{
int i,j ;
if(count==(r-1))
{
  for(j=k;jn;j++)
  {
  str[j]='1';
  if(j!=k)
  str[j-1]='0';
  printf(%s\n,str);
  }
  str[j-1]= '0';
  return ;
}
else
{
  for(i=k;i=m;i++)
  {
  str[i]='1';
  if(i!=k)str[i-1]='0';
  func(i+1,m+1,r,n,str,count+1);
  }
}
}

thanx in advance !


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: acm problem : i need help

2007-05-16 Thread Yingjie Xu
a c style string with length n needs n+1 memory space.

On 5/16/07, mirchi [EMAIL PROTECTED] wrote:


 hello people ,
 i am facing a problem in submission of The Hamming Disteance 
 problem. the output seems to be fine. but the program crashes in
 between. the error says:

 The instruction at 0x7c93426d referenced memory at 0x .
 The memory could not be read .

 and the acm feedback error says :

 Your program has died with signal 11 (SIGSEGV). Meaning:

   Invalid memory reference

 Before crash, it ran during 0.004 seconds.

 the code is as below :

 #includestdio.h
 #includestdlib.h
 void func (int k , int m , int r , int n , char *str , int count);
 int main()
 {
int i,count=0;
int noi,ij;
int r,n;
char *str;
scanf(%d,noi);
for(ij=0;ijnoi;ij++)
{
   scanf(%d %d,n,r);
   str=(char *)malloc(sizeof(char)*n);
   for(i=0;in;i++)
   {
str[i]='0';
   }
   str[n]=NULL;
   func(0,n-r,r,n,str,count);
}
return 0;
 }
 void func (int k , int m , int r , int n , char *str,int count)
 {
int i,j ;
if(count==(r-1))
{
  for(j=k;jn;j++)
  {
  str[j]='1';
  if(j!=k)
  str[j-1]='0';
  printf(%s\n,str);
  }
  str[j-1]= '0';
  return ;
}
else
{
  for(i=k;i=m;i++)
  {
  str[i]='1';
  if(i!=k)str[i-1]='0';
  func(i+1,m+1,r,n,str,count+1);
  }
}
 }

 thanx in advance !


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: acm problem : i need help

2007-05-16 Thread mirchi

that problem is solved..but now the reply is wrong answer.
the problem asks for printing the strings in ascending lexicographical
order.
wat does this mean??

On May 16, 12:55 pm, Yingjie Xu [EMAIL PROTECTED] wrote:
 a c style string with length n needs n+1 memory space.

 On 5/16/07, mirchi [EMAIL PROTECTED] wrote:



  hello people ,
  i am facing a problem in submission of The Hamming Disteance 
  problem. the output seems to be fine. but the program crashes in
  between. the error says:

  The instruction at 0x7c93426d referenced memory at 0x .
  The memory could not be read .

  and the acm feedback error says :

  Your program has died with signal 11 (SIGSEGV). Meaning:

Invalid memory reference

  Before crash, it ran during 0.004 seconds.

  the code is as below :

  #includestdio.h
  #includestdlib.h
  void func (int k , int m , int r , int n , char *str , int count);
  int main()
  {
 int i,count=0;
 int noi,ij;
 int r,n;
 char *str;
 scanf(%d,noi);
 for(ij=0;ijnoi;ij++)
 {
scanf(%d %d,n,r);
str=(char *)malloc(sizeof(char)*n);
for(i=0;in;i++)
{
 str[i]='0';
}
str[n]=NULL;
func(0,n-r,r,n,str,count);
 }
 return 0;
  }
  void func (int k , int m , int r , int n , char *str,int count)
  {
 int i,j ;
 if(count==(r-1))
 {
   for(j=k;jn;j++)
   {
   str[j]='1';
   if(j!=k)
   str[j-1]='0';
   printf(%s\n,str);
   }
   str[j-1]= '0';
   return ;
 }
 else
 {
   for(i=k;i=m;i++)
   {
   str[i]='1';
   if(i!=k)str[i-1]='0';
   func(i+1,m+1,r,n,str,count+1);
   }
 }
  }

  thanx in advance !


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: acm problem : i need help

2007-05-16 Thread Dhruva Sagar
str[n]=NULL;
I think it should be str[n-1]='\0'; (String null character).
And the loop should run from i=0;in-1.
The memory allocated would be of size n, i.e. 0 to n-1. str[n] would be
outside the allocated memory...

Correct me if i m wrong.

-- Forwarded message --
From: mirchi [EMAIL PROTECTED]
Date: May 16, 2007 2:20 PM
Subject: [algogeeks] Re: acm problem : i need help
To: Algorithm Geeks algogeeks@googlegroups.com


that problem is solved..but now the reply is wrong answer.
the problem asks for printing the strings in ascending lexicographical
order.
wat does this mean??

On May 16, 12:55 pm, Yingjie Xu [EMAIL PROTECTED] wrote:
 a c style string with length n needs n+1 memory space.

 On 5/16/07, mirchi [EMAIL PROTECTED] wrote:



  hello people ,
  i am facing a problem in submission of The Hamming Disteance 
  problem. the output seems to be fine. but the program crashes in
  between. the error says:

  The instruction at 0x7c93426d referenced memory at 0x .
  The memory could not be read .

  and the acm feedback error says :

  Your program has died with signal 11 (SIGSEGV). Meaning:

Invalid memory reference

  Before crash, it ran during 0.004 seconds.

  the code is as below :

  #includestdio.h
  #includestdlib.h
  void func (int k , int m , int r , int n , char *str , int count);
  int main()
  {
 int i,count=0;
 int noi,ij;
 int r,n;
 char *str;
 scanf(%d,noi);
 for(ij=0;ijnoi;ij++)
 {
scanf(%d %d,n,r);
str=(char *)malloc(sizeof(char)*n);
for(i=0;in;i++)
{
 str[i]='0';
}
str[n]=NULL;
func(0,n-r,r,n,str,count);
 }
 return 0;
  }
  void func (int k , int m , int r , int n , char *str,int count)
  {
 int i,j ;
 if(count==(r-1))
 {
   for(j=k;jn;j++)
   {
   str[j]='1';
   if(j!=k)
   str[j-1]='0';
   printf(%s\n,str);
   }
   str[j-1]= '0';
   return ;
 }
 else
 {
   for(i=k;i=m;i++)
   {
   str[i]='1';
   if(i!=k)str[i-1]='0';
   func(i+1,m+1,r,n,str,count+1);
   }
 }
  }

  thanx in advance !





-- 
Thanks  Regards,
Dhruva Sagar.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] maximum matching

2007-05-16 Thread mohamad momenian
Dear All

i want to solve the minimum weighted vertex-cover problem , Now  during
write that code i want a sample code for maximum matching problem please
help me by sending that sample code to me .

thanks every one.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Graph Problem

2007-05-16 Thread pramod

Here's a graph problem.

We are given a directed graph. We are allowed to change the directions
of the edges.
Our aim is to minimize the maximum degree in the graph.
How do we achieve this?

One way is to take the vertex with maximum degree, and take another
vertex with least degree reachable from this max-degree vertex and
then reverse all the edges' direction along the path. Now the
questions with this approach are (1) how do we prove that this will
lead to the optimal-graph in the sense, can we get a graph such that
it's maximum degree is the best possible?
(2) What's the time complexity, is it bound tightly?
(3) Is there any better way?

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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] please tell what is wrong with my code??

2007-05-16 Thread mirchi

i am trying the following problem.

http://acm.uva.es/p/v7/729.html

my code is as below : (it is giving a wrong answer on submission !)


#includestdio.h
#includestdlib.h
#includestring.h
struct strin
{
   char st[20];
   struct strin * next;
};
typedef struct strin stri;
void func (int k , int m , int r , int n , char *str , int count ,stri
**first);
void add(char *str,stri **first);
void prin(stri **first);
int main()
{
stri *first=NULL;
int i,count=0;
int noi,ij;
int r,n;
char *str;
scanf(%d,noi);
for(ij=0;ijnoi;ij++)
{
   scanf(%d %d,n,r);
   str=(char *)malloc(sizeof(char)*(n+1));
   for(i=0;in;i++)
   {
str[i]='0';
   }
   str[n]='\0';
   func(0,n-r,r,n,str,count,first);
   prin(first);
   printf(\n);
   first=NULL;
}
system(pause);
return 0;
}
void func (int k , int m , int r , int n , char *str,int count,stri
**first)
{
int i,j ;
if(count==(r-1))
{
  for(j=k;jn;j++)
  {
  str[j]='1';
  if(j!=k)
  str[j-1]='0';
  add(str,first);
  }
  str[j-1]= '0';
  return ;
}
else
{
  for(i=k;i=m;i++)
  {
  str[i]='1';
  if(i!=k)str[i-1]='0';
  func(i+1,m+1,r,n,str,count+1,first);
  }
}
}
void add(char *str,stri **first)
{
 static stri *p=NULL;
 if((*first)==NULL)
 {
   *first=(stri *)malloc(sizeof(stri));
   strcpy((*first)-st,str);
   (*first)-next=NULL;
   p=*first;
 }
 else
 {
 (p-next)=(stri *)malloc(sizeof(stri));
 p=p-next;
 strcpy(p-st,str);
 p-next=NULL;
 }
}
void prin(stri **first)
{
 if((*first)==NULL)
 return;
 else
 {
   prin(((*first)-next));
   printf(%s\n,(*first)-st);
 }
}


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: acm problem : i need help

2007-05-16 Thread mirchi

the link is http://acm.uva.es/p/v7/729.html
try the problem..
mine is giving a wrong answer...
but my output seems to be fine.

#includestdio.h
#includestdlib.h
#includestring.h
struct strin
{
   char st[20];
   struct strin * next;
};
typedef struct strin stri;
void func (int k , int m , int r , int n , char *str , int count ,stri
**first);
void add(char *str,stri **first);
void prin(stri **first);
int main()
{
stri *first=NULL;
int i,count=0;
int noi,ij;
int r,n;
char *str;
scanf(%d,noi);
for(ij=0;ijnoi;ij++)
{
   scanf(%d %d,n,r);
   str=(char *)malloc(sizeof(char)*(n+1));
   for(i=0;in;i++)
   {
str[i]='0';
   }
   str[n]='\0';
   func(0,n-r,r,n,str,count,first);
   prin(first);
   printf(\n);
   first=NULL;
}
system(pause);
return 0;
}
void func (int k , int m , int r , int n , char *str,int count,stri
**first)
{
int i,j ;
if(count==(r-1))
{
  for(j=k;jn;j++)
  {
  str[j]='1';
  if(j!=k)
  str[j-1]='0';
  add(str,first);
  }
  str[j-1]= '0';
  return ;
}
else
{
  for(i=k;i=m;i++)
  {
  str[i]='1';
  if(i!=k)str[i-1]='0';
  func(i+1,m+1,r,n,str,count+1,first);
  }
}
}
void add(char *str,stri **first)
{
 static stri *p=NULL;
 if((*first)==NULL)
 {
   *first=(stri *)malloc(sizeof(stri));
   strcpy((*first)-st,str);
   (*first)-next=NULL;
   p=*first;
 }
 else
 {
 (p-next)=(stri *)malloc(sizeof(stri));
 p=p-next;
 strcpy(p-st,str);
 p-next=NULL;
 }
}
void prin(stri **first)
{
 if((*first)==NULL)
 return;
 else
 {
   prin(((*first)-next));
   printf(%s\n,(*first)-st);
 }
}




On May 16, 2:16 pm, Dhruva Sagar [EMAIL PROTECTED] wrote:
 I don't know about this...Can you tell me the site where your trying to
 submit this problem?
 Is it some local (LAN) setup where you are having this submissions as a part
 of some competition or is it in the internet? If in the internet give me the
 link i'll see if i can find something...

 On 5/16/07, mirchi [EMAIL PROTECTED] wrote:





  u r rite..but now tht prblem is solved the problem i am facing to
  submit the code is that it does not print the code in lexicographical
  order...

  On May 16, 1:56 pm, Dhruva Sagar [EMAIL PROTECTED] wrote:
   str[n]=NULL;
   I think it should be str[n-1]='\0'; (String null character).
   And the loop should run from i=0;in-1.
   The memory allocated would be of size n, i.e. 0 to n-1. str[n] would be
   outside the allocated memory...

   Correct me if i m wrong.

   -- Forwarded message --
   From: mirchi [EMAIL PROTECTED]
   Date: May 16, 2007 2:20 PM
   Subject: [algogeeks] Re: acm problem : i need help
   To: Algorithm Geeks algogeeks@googlegroups.com

   that problem is solved..but now the reply is wrong answer.
   the problem asks for printing the strings in ascending lexicographical
   order.
   wat does this mean??

   On May 16, 12:55 pm, Yingjie Xu [EMAIL PROTECTED] wrote:
a c style string with length n needs n+1 memory space.

On 5/16/07, mirchi [EMAIL PROTECTED] wrote:

 hello people ,
 i am facing a problem in submission of The Hamming Disteance 
 problem. the output seems to be fine. but the program crashes in
 between. the error says:

 The instruction at 0x7c93426d referenced memory at 0x .
 The memory could not be read .

 and the acm feedback error says :

 Your program has died with signal 11 (SIGSEGV). Meaning:

   Invalid memory reference

 Before crash, it ran during 0.004 seconds.

 the code is as below :

 #includestdio.h
 #includestdlib.h
 void func (int k , int m , int r , int n , char *str , int count);
 int main()
 {
int i,count=0;
int noi,ij;
int r,n;
char *str;
scanf(%d,noi);
for(ij=0;ijnoi;ij++)
{
   scanf(%d %d,n,r);
   str=(char *)malloc(sizeof(char)*n);
   for(i=0;in;i++)
   {
str[i]='0';
   }
   str[n]=NULL;
   func(0,n-r,r,n,str,count);
}
return 0;
 }
 void func (int k , int m , int r , int n , char *str,int count)
 {
int i,j ;
if(count==(r-1))
{
  for(j=k;jn;j++)
  {
  str[j]='1';
  if(j!=k)
  

[algogeeks] Re: Graph Problem

2007-05-16 Thread Rajiv Mathews

Could you please explain the question.

Typically in a directed graph we talk of in-degree and out-degree for
a vertex. So is the question then to minimize the maximum of these in
all vertices of the graph? If so what operations are permitted?

On 5/16/07, pramod [EMAIL PROTECTED] wrote:

 Here's a graph problem.

 We are given a directed graph. We are allowed to change the directions
 of the edges.
 Our aim is to minimize the maximum degree in the graph.
 How do we achieve this?

 One way is to take the vertex with maximum degree, and take another
 vertex with least degree reachable from this max-degree vertex and
 then reverse all the edges' direction along the path. Now the
 questions with this approach are (1) how do we prove that this will
 lead to the optimal-graph in the sense, can we get a graph such that
 it's maximum degree is the best possible?
 (2) What's the time complexity, is it bound tightly?
 (3) Is there any better way?

 Thanks


 



-- 


Regards,
Rajiv Mathews

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---