| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
一个程序壳?@@@@ @@@ @@@@
@ @ @ @ @
@ @ @ @ @
@@@@ @ @ @
@ @ @ @ @
@ @ @ @ @
@ @@@ @@@
#include <cstdio>
#include <string.h>
#include <vector>
#include <map>
#include <iostream>
using namespace std;
const int NMax=30;
int N,L1,L2,connect[NMax];
bool ok[NMax],sta[NMax];
map<string,int> ID1,ID2;
map<int,string> rev1,rev2;
map<int,bool> State;
vector<int> G[NMax];
bool DFS(int a) {
sta[a]=1;
for(int p=0;p<G[a].size();p++) {
if(!connect[G[a][p]]) {
ok[a]=1;
return 1;
}else if(!sta[connect[G[a][p]]] && DFS(connect[G[a][p]])) {
ok[a]=1;
connect[G[a][p]]=a;
return 1;
}
}
return 0;
}
int main()
{
string tmp;
char buf[NMax],buf2[NMax];
scanf("%d",&N);
for(int i=1;i<=N;i++) {
scanf("%s",buf);
int len=strlen(buf);tmp.clear();
for(int i=0;i<len;i++) tmp.push_back(buf[i]);
ID2[tmp]=++L2;rev2[L2]=tmp;
}
while(scanf("%s",buf),(buf[0]!='Q')) {
scanf("%s",buf2);
int len=strlen(buf2);tmp.clear();
for(int i=0;i<len;i++) tmp.push_back(buf2[i]);
if(buf[0]=='M') {
int ID=ID2[tmp];
for(map<int,bool>::iterator p=State.begin();p!=State.end();p++) if(p->second)
G[p->first].push_back(ID);
continue;
}
if(ID1[tmp]==0) {ID1[tmp]=++L1;rev1[L1]=tmp;}
int ID=ID1[tmp];
if(buf[0]=='E') State[ID]=1;
else if(buf[0]=='L') State[ID]=0;
}
//puts("dsdfsdf");
for(int i=1;i<=L1;i++) connect[i]=0;
for(int i=1;i<=L2;i++) ok[i]=0;
for(int i=1;i<=L2;i++) {
for(int p=0;p<G[i].size();p++) {
if(!connect[G[i][p]]) {
connect[G[i][p]]=i;
ok[i]=1;
break;
}
}
}
for(int i=1;i<=L2;i++) {
for(int j=1;j<=L2;j++) sta[j]=0;
if(!ok[i]) DFS(i);
}
for(int i=1;i<=L1;i++) {
if(connect[i]) cout <<rev1[i]<<':'<<rev2[connect[i]]<<endl;
else cout <<rev1[i]<<':'<<"???"<<endl;
}
while(1)getchar();getchar();
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator