讨论 / AC 纪念
lani711 2015-12-09 23:41:30
点我顶贴 收藏 删除
var guilty:array[1..20] of longint;lie:array[1..20] of boolean;

judged:array[1..20] of boolean;comb:array[0..20] of longint;nam:array[1..20] of string;

words:array[1..100] of string;m,n,p:longint;now:longint;ans:longint;junk:boolean;

procedure init;

var i:longint;

begin

readln(m,n,p);

for i:=1 to m do readln(nam[i]);

for i:=1 to p do readln(words[i]);

end;

function nam2loc(tmp:string):longint;

var

i:longint;

begin

for i:=1 to m do

if tmp=nam[i] then exit(i);

end;

function words2day(tmp:string):longint;

begin

if tmp='Monday' then

exit(1)

else

if tmp='Tuesday' then

exit(2)

else

if tmp='Wednesday' then

exit(3)

else

if tmp='Thursday' then

exit(4)

else

if tmp='Friday' then

exit(5)

else

if tmp='Saturday' then

exit(6)

else

exit(7);

end;

procedure findcri;

var

beguilty,beinnocent,beunknown,criminal,i:longint;

begin

beguilty:=0;

beinnocent:=0;

beunknown:=0;

for i:=1 to m do

if guilty[i]=0 then

inc(beunknown)

else

if guilty[i]=-1 then

inc(beinnocent)

else

inc(beguilty);

if not((beguilty=1)or((beinnocent=m-1)and(beunknown=1))) then exit;

if beguilty=1 then

begin

for i:=1 to m do

if guilty[i]=1 then criminal:=i;

end

else

for i:=1 to m do

if guilty[i]=0 then criminal:=i;

if judged[criminal] then exit;

judged[criminal]:=true;

if ans=0 then

ans:=criminal

else

ans:=maxlongint;

end;

procedure judge;

var

tmpwords:string;

tmpp,tmploc,tmploc2,tmpday,day,i:longint;

begin

for i:=1 to m do guilty[i]:=0;

day:=0;

for i:=1 to p do

begin

tmpp:=pos(': ',words[i]);

tmploc:=nam2loc(copy(words[i],1,tmpp-1));

tmpwords:=copy(words[i],tmpp+2,length(words[i])-tmpp-1);

if tmpwords='I am guilty.' then

begin

junk:=false;

if lie[tmploc] then

if guilty[tmploc]=1 then exit else guilty[tmploc]:=-1

else

if guilty[tmploc]=-1 then exit else guilty[tmploc]:=1;

end

else

if tmpwords='I am not guilty.' then

begin

junk:=false;

if lie[tmploc] then

if guilty[tmploc]=-1 then exit else guilty[tmploc]:=1

else

if guilty[tmploc]=1 then exit else guilty[tmploc]:=-1;

end

else

begin

tmpp:=pos(' is guilty.',tmpwords);

if tmpp<>0 then

begin

junk:=false;

tmploc2:=nam2loc(copy(tmpwords,1,tmpp-1));

if lie[tmploc] then

if guilty[tmploc2]=1 then exit else guilty[tmploc2]:=-1

else

if guilty[tmploc2]=-1 then exit else guilty[tmploc2]:=1;

end

else

begin

tmpp:=pos(' is not guilty.',tmpwords);

if tmpp<>0 then

begin

junk:=false;

tmploc2:=nam2loc(copy(tmpwords,1,tmpp-1));

if lie[tmploc] then

if guilty[tmploc2]=-1 then exit else guilty[tmploc2]:=1

else

if guilty[tmploc2]=1 then exit else guilty[tmploc2]:=-1;

end

else

begin

tmpp:=pos('Today is ',tmpwords);

if tmpp<>0 then

begin

junk:=false;

tmpday:=words2day(copy(tmpwords,tmpp+9,length(tmpwords)-10));

if lie[tmploc] then

begin

if tmpday=day then exit;

end

else

if day=0 then

day:=tmpday

else

if tmpday<>day then exit;

end;

end;

end;

end;

end;

if (day<>now)and(day<>0) then exit;

findcri;

end;

procedure work(dep:longint);

var

i:longint;

begin

if dep>n then

begin

fillchar(lie,sizeof(lie),false);

for i:=1 to n do lie[comb[i]]:=true;

judge;

exit;

end;

for i:=comb[dep-1]+1 to m-n+dep do

begin

comb[dep]:=i;

work(dep+1);

end;

end;

procedure main;

var

i:longint;

begin

ans:=0;

junk:=true;

fillchar(judged,sizeof(judged),false);

for i:=1 to 7 do

begin

now:=i;

comb[0]:=0;

work(1);

end;

if (m=1)and(junk) then

writeln(nam[1])

else

if junk then

writeln('Cannot Determine')

else

if ans=0 then

writeln('Impossible')

else

if ans=maxlongint then

writeln('Cannot Determine')

else

writeln(nam[ans]);

end;

begin

init;

main;

end.

查看更多回复
提交回复