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

贴个码

Posted by lzy_Dennis at 2023-09-14 20:41:35 on Problem 3487
In Reply To:同是逛wa,求解释。。。 Posted by:zwliu at 2012-07-04 20:31:01
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<stdlib.h>
#include<time.h>
#include <iomanip>
#define lowbit(x) (x&(-x))
#define inf  0x7fffffff
#define linf 0x7fffffffffffffff
#define mem(x,y) memset(x,y,sizeof(x))
#define fup(i,x,y) for(int i=(x);i<=(y);i++)
#define fdn(i,x,y) for(int i=(x);i>=(y);i--)
#define sp(x) setprecision(x)
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define sc(n) scanf("%s",n)
#define lowbit(x) (x&(-x))
#define pf(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define pff(x) printf("%lf\n",x)
#define pcc(x,y) printf("%c %c\n",x,y)
#define debug printf("!!\n");
#define N 1000005
#define M 4000009
#define pi acos(-1)
#define eps 1e-2
using namespace std;
typedef long long ll;
typedef double db;
int men[35][35],women[35][35];
int manperfer[35],num[35],womennow[35];
stack<int> s;
map<char,int> ma,wo;
char c1[35],c2[35];
int n;
void ini() {
	mem(manperfer,0);
	mem(womennow,0);
}
int fi(int x,int y) {
	fup(i,1,n)
	if(women[x][i]==y) return i;
	return 0;
}
void choose(int x) {
	int prefer=men[x][num[x]];
	if(womennow[prefer]==0) {
		womennow[prefer]=x;
		manperfer[x]=prefer;
		return ;
	}
	int old=fi(prefer,womennow[prefer]);
	int now=fi(prefer,x);
	if(old<now) {
		num[x]++;
		s.push(x);
	} else {
		int tp=womennow[prefer];
		num[tp]++;
		s.push(tp);
		womennow[prefer]=x;
		manperfer[x]=prefer;
	}
}
int main() {
	int t;
	sd(t);
	while(t--) {
		ini();
		sd(n);
		fup(i,1,n)
		sc(c1+i),num[i]=1;
		sort(c1+1,c1+1+n);
		fup(i,1,n)
		ma[c1[i]]=i;

		fup(i,1,n)
		sc(c2+i);
		sort(c2+1,c2+1+n);
		fup(i,1,n)
		wo[c2[i]]=i;
		char like[35];
		fup(j,1,n) {
			sc(like);
			fup(i,2,n+1) {
				char x;
				x=like[i];
				men[ma[like[0]]][i-1]=wo[x];

			}
		}
		fup(j,1,n) {
			sc(like);
			fup(i,2,n+1) {
				char x;
				x=like[i];
				women[wo[like[0]]][i-1]=ma[x];
			}
		}
		fup(i,1,n)
		choose(i);
		while(!s.empty()) {
			int tp=s.top();
			s.pop();
			choose(tp);
		}
		fup(i,1,n)
		pcc(c1[i],c2[manperfer[ma[c1[i]]]]);
		puts("");
	}
	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