×

STABLEMP STABLEMP

hola amigos, i could not find out wts the problem with this code for stable marriage problem which is pretty straight forward.any help will be appreciated.

include<stdlib.h>

using namespace std;

int n;

bool preferw(int w,int m,int m1,int n,int wo) { for(int i=1;i<n;i++) { if(((wo+w(n-1) + i))==m)return true; if(((wo+w*(n-1) + i))==m1)return false; } return false; }

bool preferm(int m,int w,int w1,int n,int me) { for(int i=1;i<n;i++) { if(((me+m(n-1) + i))==w)return true; if(((me+m*(n-1) + i))==w1)return false; } return false; }

int main() {
int tn=0; cin>>tn; while (tn--) { int i,j=0; cin>>n;int x; int wo[n+1][n+1];int me[n+1][n+1]; for(i=1;i<=n;i++) { cin>>x; for(j=1;j<=n;j++)cin>>wo[i][j]; }

for(i=1;i<=n;i++)
{   cin>>x;
for(j=1;j<=n;j++)cin>>me[i][j];
}
int husbandof[n+1]={1};
int wifeof[n+1]={1};
int w,m=1;int a=0;
for(w=1;w<=n;w++)
{
for(m=1;m<=n;m++)
{
if(preferw(w,m,husbandof[w],n+1,(int* )wo)==true && preferm(m,w,wifeof[m],n+1,(int* )me)== true)
husbandof[w]=m;wifeof[m]=w;cout<<a++<<endl;
}
}
for(m=1;m<=n;m++)cout << " " << m << " "<<wifeof[m] << endl;
}
return 0;


}

1
accept rate: 0%

 0 post problem link answered 25 May '18, 15:01 3★code_man 4●6 accept rate: 8%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×169
×1

question asked: 25 May '18, 14:55

question was seen: 82 times

last updated: 25 May '18, 16:18