题目有点烦,有点绕。代码:
type room= record
f:0..1;
p:longint;
end;
var n,m,i,j,k,start,ans,len,t:longint;
arr1:array[1..10000,0..99] of room;
arr2:array[0..105] of longint;
function find(l,r,tt:integer):integer;
var mid:integer;
begin
while l<=r do
begin
mid:=(l+r)div 2;
ifarr2[mid]=tt then exit(mid);
if arr2[mid]{不知道为什么后面这行代码总是会被屏蔽掉,所以截个图}
elser:=mid-1;
end;
end;
begin
readln(n,m);
for i:=1 to n do
begin
for j:=0 tom-1 do
begin
readln(arr1[i,j].f,arr1[i,j].p);
end;
end;
readln(start);
for i:=1 to n do
begin
ans:=(ans+arr1[i,start].p) mod 20123;
len:=0;
for j:=0 tom-1 do
begin
if arr1[i,j].f=0 then continue;
arr2[len]:=j;
inc(len);
end;
dec(len);
j:=start;
whilearr1[i,j].f=0 do
begin
if j=m-1 then j:=0
else inc(j);
end;
k:=find(0,len,j);
t:=(k+arr1[i,start].p-1) mod (len+1);
start:=arr2[t];
end;
writeln(ans);
end.