zoukankan      html  css  js  c++  java
  • 【codevs1049】

    没被使用的ID谁都有可能会用到;

    而当匹配后,自己的ID还可以和其他人的换时,

    即并不能确定两个ID和两个名字的关系时,这两个人的ID均未知。

    var
    w:array[1..20,1..20] of boolean;
    ID:array[1..20] of string;
    nm,ans:array[1..20] of string;
    room2,used:array[1..20] of boolean;
    r,tr:array[1..20] of longint;
    N,i,j,p,tmp:longint;
    cc:char;
    ss:string;
    function checkname(s:string):longint;
    var
    i:longint;
    begin
    for i:=1 to p do
      if nm[i]=s then
       exit(i);
    inc(p);
    nm[p]:=s;
    checkname:=p;
    end;
    function checkID(s:string):longint;
    var
    i:longint;
    begin
    for i:=1 to n do
      if ID[i]=s then
       exit(i);
    end;
    function dfs(p:longint):boolean;
    var
    i:longint;
    begin
    if p=0 then
      exit(false);
    for i:=1 to n do
      if w[p,i] and not(used[i]) then
      begin
       used[i]:=true;
       if (r[i]=0) or dfs(r[i]) then
       begin
        r[i]:=p;
        exit(true);
       end;
      end;
    dfs:=false;
    end;
    begin
    readln(N);
    for i:=1 to n do
      for j:=1 to n do
       w[i,j]:=true;
    for i:=1 to n-1 do
    begin
      setlength(ID[i],20);
      read(cc);j:=0;
      while cc<>' ' do
      begin
       inc(j);
       ID[i][j]:=cc;
       read(cc);
      end;
      setlength(ID[i],j);
    end;
    readln(ID[n]);
    readln(ss);
    while ss<>'Q' do
    begin
      case ss[1] of
      'E':begin
        delete(ss,1,2);
        room2[checkname(ss)]:=true;
       end;
      'L':begin
        delete(ss,1,2);
        room2[checkname(ss)]:=false;
       end;
      'M':begin
        delete(ss,1,2);
        tmp:=checkID(ss);
        for i:=1 to n do
         if not room2[i] then
         begin
          w[tmp,i]:=false;
         //writeln('del ',tmp,' ',i); //debug
         end;
       end;
      end;
      readln(ss);
    end;
    for i:=1 to n do
    begin
      fillchar(used,sizeof(used),0);
      dfs(i);
    end;
    for i:=1 to n do
      if r[i]>0 then
      begin
       tr:=r;
       w[r[i],i]:=false;
       r[i]:=0;
       fillchar(used,sizeof(used),0);
       if dfs(tr[i]) then
        ans[i]:=nm[i]+':???'
       else
        ans[i]:=nm[i]+':'+ID[tr[i]];
       r:=tr;
       w[r[i],i]:=true;
      end;
    for i:=1 to n-1 do
      for j:=i+1 to n do
       if ans[i]>ans[j] then
       begin
        ss:=ans[i];
        ans[i]:=ans[j];
        ans[j]:=ss;
       end;
    for i:=1 to n do
      writeln(ans[i]);
    end.

       喜欢就收藏一下,vic私人qq:1064864324,加我一起讨论问题,一起进步^-^

  • 相关阅读:
    java异常
    Map集和
    获取每个字符出现的次数
    从1-33号球中选取6个红球,且红球数字最多重复不超过3个 从1-16号球中选取一个篮球 由红球和蓝球共同组成一个双色球号码,且红球在左边(按照升序排列),篮球在右边。
    gitlab介绍及使用
    Maven使用介绍
    IDEA集成开发环境安装git,修改代码后文件变色代表的含义
    大数据相关
    开源镜像站汇总
    MySQL配置文件详解
  • 原文地址:https://www.cnblogs.com/victorslave/p/4823914.html
Copyright © 2011-2022 走看看