1 条题解
-
0
Pascal :
var st:ansistring;f:array[0..35000,0..100] of longint; l,a,b:array[0..100000] of longint; tt,t,h,i,k:longint; function try(t:longint):longint; var i:longint; begin if b[t]>=0 then begin try:=b[t];exit;end; try:=try(f[t,1]); for i:=2 to f[t,0] do begin if l[t] mod 2=1 then try:=try and try(f[t,i]); if l[t] mod 2=0 then try:=try or try(f[t,i]); // writeln(t,' ',try); end; end; begin //assign(input,'form.in');reset(input); //assign(output,'form.out');rewrite(output); readln(st); while st<>'()' do begin h:=h+1; fillchar(l,sizeof(l),0); fillchar(a,sizeof(a),0); fillchar(b,sizeof(b),0); for i:=0 to 35000 do f[i,0]:=0; b[i]:=0; tt:=0;t:=0;b[0]:=-1; for i:=1 to length(st) do begin if (st[i]='F')or(st[i]='T') then begin t:=t+1; a[t]:=tt; f[tt,0]:=f[tt,0]+1; k:=f[tt,0]; f[tt,k]:=t; if st[i]='F' then b[t]:=0 else b[t]:=1; l[t]:=l[tt]+1; end; if st[i]='(' then begin t:=t+1; f[tt,0]:=f[tt,0]+1; k:=f[tt,0]; a[t]:=tt; f[tt,k]:=t; b[t]:=-1; l[t]:=l[tt]+1; tt:=t; end; if st[i]=')' then tt:=a[tt]; end; write(h,'. '); if try(1)=1 then writeln('true') else writeln('false'); readln(st); end; close(input);close(output); end.
- 1
信息
- ID
- 4218
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者