You are not logged in. Please login at www.codechef.com to post your questions!

×

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

include <cassert>

include <cstdio>

include <algorithm>

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;

}

asked 25 May '18, 14:55

invincible200's gravatar image

2★invincible200
1
accept rate: 0%


post problem link

link

answered 25 May '18, 15:01

code_man's gravatar image

3★code_man
46
accept rate: 8%

LINKlink text

link

answered 25 May '18, 16:18

invincible200's gravatar image

2★invincible200
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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