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 yc5_yc at 2012-08-04 20:32:06 on Problem 1043
    //   ) ) //   ) )       / /           //   ) ) //   ) )  //   ) ) 
   //___/ / //   / /       / /           //   / / //___/ /  //        
  / ____ / //   / /       / /           //   / / / ___ (   //  ____   
 //       //   / /       / /           //   / / //   | |  //    / /   
//       ((___/ /  ((___/ /       ()  ((___/ / //    | | ((____/ /    
#include <cstdio>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#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;
bool G[NMax][NMax];
bool DFS(int a) {
    sta[a]=1;
    for(int j=1;j<=N;j++) if(G[a][j]){
        if(!connect[j]) {
            connect[j]=a;
            ok[a]=1;
            return 1;
        }else if(!sta[connect[j]] && DFS(connect[j])) {
            ok[a]=1;
            connect[j]=a;
            return 1;
        }
    }
    return 0;
}
int sth() {
    for(int i=1;i<=N;i++) connect[i]=0;
    for(int i=1;i<=N;i++) ok[i]=0;
    for(int i=1;i<=N;i++) {
        for(int j=1;j<=N;j++) if(G[i][j]){
            if(!connect[j]) {
                connect[j]=i;
                ok[i]=1;
                break;
            }
        }
    }
    int ret=0;
    for(int i=1;i<=N;i++) {
        for(int j=1;j<=N;j++) sta[j]=0;
        if(!ok[i] && DFS(i)) ret++;
    }
    return ret;
}
bool cmp(int a,int b) {
    return rev1[a]<rev1[b];
}
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 j=0;j<len;j++) tmp.push_back(buf[j]);
        ID2[tmp]=++L2;rev2[L2]=tmp;    
    }
    for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) G[i][j]=1;
    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];
            int Maxn=-1;
            for(map<int,bool>::iterator p=State.begin();p!=State.end();p++) { 
                if(!p->second) G[ID][p->first]=0;
                else if(p->first>Maxn) Maxn=p->first;
            } 
            for(int i=Maxn+1;i<=N;i++) G[ID][i]=0;
            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");
    int R[NMax];
    for(int i=1;i<=N;i++) {
        R[i]=-1;
        for(int j=1;j<=N;j++) if(G[j][i]){
            G[j][i]=0;
            if(sth()<N) {
                R[i]=j;
                G[j][i]=1;
                、、puts("Here");
                break;
            }
            G[j][i]=1;
        }
    }
    for(int i=1;i<=N;i++) {
        if(R[i]!=-1) cout <<rev1[i]<<':'<<rev2[R[i]]<<endl;
        else cout <<rev1[i]<<':'<<"???"<<endl;
    }
    while(1)getchar(); getchar();
    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