Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

狂wa,不知道错哪了。。。哪位大牛帮忙看看,不剩感激

Posted by celia01 at 2012-05-08 16:50:34 on Problem 3487 and last updated at 2012-05-08 17:24:17
题目主要思路就是套用的吉大模板~~ 自己感觉也是正确的,不知道为什么总错

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define see(x) cout<<#x<<":"<<x<<endl;
using namespace std;
const int N = 30;
struct People{
	bool state;
	int opp;
	int tag;
	int list[N];
	int priority[N];
	void Ini(){state=false; tag=0;}
}man[N], woman[N];
int cman[N], cwoman[N];
char ccman[N], ccwoman[N];
struct R{
	int opp, own;
}request[N];
struct Sortt{
	char man, woman;
	bool operator < (const Sortt &a) const{
		return man<a.man;
	}
}sortt[N];
int n;
void stableMatching(){
	int k, i, idd;
	for(k=0;k<n;k++){
		idd=0;
		for(i=0;i<n;i++){
			if(man[i].state==0){
				request[idd].opp = man[i].list[man[i].tag];//自由man[i]想结合的woman编号 
				request[idd].own = i;  //自由的man的编号 
				man[i].tag ++; 
				idd++;
			}
		}
		if(idd==0) break;
		for(i=0;i<idd;i++){
			if(woman[request[i].opp].state==0){  //woman是自由的 
				woman[request[i].opp].opp = request[i].own;//woman的约会对象编号 
				woman[request[i].opp].state = 1;
				man[request[i].own].opp = request[i].opp;//man的约会对象编号
				man[request[i].own].state = 1;
			}
			else{
				if(woman[request[i].opp].priority[woman[request[i].opp].opp] > woman[request[i].opp].priority[request[i].own] ){ //
					//现配偶的优先级编号>此时的man   即优先级落后于此man 
					man[woman[request[i].opp].opp].state = 0;//解放woman现配偶 
					woman[request[i].opp].opp = request[i].own;
					man[request[i].own].opp = request[i].opp;
					man[request[i].own].state = 1;
				}
			}
		}
	}
}

int main(){
	int T, t, i, j, k, l, m;
	char ch, tmp;
	scanf("%d",&T);
	for(t=0;t<T;t++){
	//	memset(man,0,sizeof(man));
	//	memset(woman,0,sizeof(woman));
		scanf("%d",&n);
		for(i=0;i<n;i++){
			getchar();
			scanf("%c",&ch);
			cman[ch-'a'] = i;
			ccman[i] = ch;
		}
		for(i=0;i<n;i++){
			getchar();
			scanf("%c",&ch);
			cwoman[ch-'A'] = i;
			ccwoman[i] = ch;
		}
		for(i=0;i<n;i++){
			getchar();
			scanf("%c:",&tmp);
			int d = cman[tmp-'a'];
			man[d].Ini();
			for(j=0;j<n;j++){
				scanf("%c",&ch);
				man[d].list[j] = cwoman[ch-'A'];
			}
		}
		for(i=0;i<n;i++){
			getchar();
			scanf("%c:",&tmp);
			int d = cwoman[tmp-'A'];
			woman[d].Ini();
			for(j=0;j<n;j++){
				scanf("%c",&ch);
				woman[d].priority[cman[ch-'a']]= j;
			}
		}
		stableMatching();
		for(i=0;i<n;i++){
			sortt[i].man = ccman[i]; sortt[i].woman = ccwoman[man[i].opp];
		}
		sort(sortt,sortt+n);
		for(i=0;i<n;i++){
			printf("%c %c\n",sortt[i].man,sortt[i].woman);
		}
		cout<<endl; 
	}
	return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator