wikioi p1099 字串变换

还是字符串,继续贴pascal。

还是对不起咯~

博客正在慢慢写。

目前的题目难度的确不是很高。

但是难得我也不会。

所以我会发一些有难度但是不至于我们做不出来的题目。(ms.27的朋友们)

type jj=record
    s:string;
    d:longint;
end;
var
head,tail:array[1..2] of longint;
q:array[1..10000,1..2] of jj;
all,b,i:longint;
st:string;
a:array[1..10,1..2] of string;
procedure check(st:string;t:longint);
var
i:longint;
pd:boolean;
begin
pd:=false;
for i:=1 to tail[t]-1 do
if q[i,t].s=st then pd:=true;
if pd then dec(tail[t])
        else
        for i:=1 to tail[3-t] do
        if q[i,3-t].s=st then
        begin
          writeln(q[tail[t],t].d+q[i,3-t].d);
          halt;
        end;
end;
procedure expand(t:longint);
var
i:longint;
begin
for i:=2 to all do
begin
    b:=pos(a[i,t],q[head[t],t].s);
    if b<>0 then
    begin
      repeat
        inc(tail[t]);
        q[tail[t],t].s:=q[head[t],t].s;
        delete(q[tail[t],t].s,b,length(a[i,t]));
        insert(a[i,3-t],q[tail[t],t].s,b);
        q[tail[t],t].d:=q[head[t],t].d+1;
        check(q[tail[t],t].s,t);
        b:=b+pos(a[i,t],copy(q[head[t],t].s,b+1,length(q[head[t],t].s)-b));
      until pos(a[i,t],copy(q[head[t],t].s,b+1,length(q[head[t],t].s)-b))=0;
    end;
end;
inc(head[t]);
end;
procedure init;
begin
while not eoln do
begin
    inc(all);
    readln(st);
    b:=pos(' ',st);
    a[all,1]:=copy(st,1,b-1);
    a[all,2]:=copy(st,b+1,length(st)-b);
end;
q[1,1].s:=a[1,1];
q[1,2].s:=a[1,2];
head[1]:=1; tail[1]:=1;
head[2]:=1; tail[2]:=1;
repeat
    if (head[1]<=tail[1]) and (q[tail[1],1].d<=10) and (tail[1]<=tail[2]) then expand(1);
    if (head[2]<=tail[2]) and (q[tail[2],2].d<=10) and (tail[1]>tail[2]) then expand(2);
until ((head[1]>tail[1]) or (head[2]>tail[2])) or (q[tail[1],1].d+q[tail[2],2].d>10);
end;
begin
init;
writeln('NO ANSWER!');
end.
		


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值