Main topic:
There is nothing to say, stable marital problems.
Problem Solving Ideas:
First, all the men are pressed into the queue once, for each man's i , first out of the team, looking in order from his liking, if there was a woman t There is no match or match for the current J Better than this guy, then let i,t Match, and then set the J Join the queue, if not found, will i Rejoin the queue.
AC Code:
#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <iostream>#include <map>#include <string>#include <queue>using namespace STD; Map <string,int>Man Map <string,int>Womanstringwname[810];stringmname[810];intNintnum=0;intgm[810][810]={{0}};intgw[810][810]={{0}};intlinkm[810]={0};intlinkw[810]={0};intMain () {Ios::sync_with_stdio (0);Cin>>N; for(intI=1; i<=n;i++) {Cin>>mname[i]; Man[mname[i]]=i; for(intj=1; j<=n;j++) {stringChCin>>ch;if(!woman[ch]) {woman[ch]=++num; Wname[num]=ch; } Gm[i][j]=woman[ch]; } } for(intI=1; i<=n;i++) {stringChCin>>ch;intGG=WOMAN[CH]; Wname[gg]=ch; for(intj=1; j<=n;j++) {Cin>>ch; Gw[gg][man[ch]]=j; } } Queue <int>Que; for(intI=1; i<=n;i++) Que.push (i); for(;! Que.empty ();) {intCnt=que.front (); Que.pop ();intI for(i=1; i<=n;i++) {intGg=gm[cnt][i];if(linkw[gg]==0) {linkw[gg]=cnt; Linkm[cnt]=gg; Break; }Else if(Gw[gg][cnt]<gw[gg][linkw[gg]]) {Que.push (Linkw[gg]); linkw[gg]=cnt; Linkm[cnt]=gg; Break; } }if(i>n) Que.push (CNT); }cout<<"YES"<<endl; for(intI=1; i<=n;i++)cout<<mname[i]<<"'<<wname[Linkm[i]]<<endl;return 0;}
sgu-264. Travel