Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

帮忙研究下。。谢谢。。。。。。。。。。

Posted by tempp at 2007-03-14 17:29:41 on Problem 1282
var
   n,p:integer;
   t:array[0..199,0..199]of integer;
   b:array[0..199,0..199]of boolean;
   d:array[0..199]of longint;


procedure init;
var
   i,j:integer;
begin
  readln(n,p);
  for i:=0 to n-1 do
    begin
      for j:=0 to p-1 do read(t[i,j]);
      readln;
    end;
end;

procedure turn;
var
   i,j,te:integer;
begin
  for i:=0 to n-1 do
    for j:=0 to (p-1) div 2 do
     begin
       te:=t[i,j]-1; t[i,j]:=t[i,p-j-1]-1;t[i,p-j-1]:=te end;
end;

procedure find;
var
  i,j,k,x,ans:longint;
begin
  i:=d[0];ans:=d[0]; x:=0;
  for j:=1 to n-1 do
   begin
    k:=d[j];
    while (i<>k) do
     begin
      i:=abs(i-k);
      x:=i;i:=k;k:=x
     end;
     ans:=ans*d[j] div i;
     i:=ans;
    end;
   write(ans);
end;

procedure work;
var
  i,j,k,te:integer;
begin
  init;
  turn;
  k:=0;
  for i:=0 to n-1 do if (t[i,0]=t[i,1])and(t[i,0]=i) then inc(k);
  if k=n then write('1')
  else begin
  fillchar(d,sizeof(d),0);
  for i:=0 to n-1 do
    begin
     j:=1;
     fillchar(b,sizeof(b),false);
      d[i]:=-1;
      k:=i;
      repeat
        inc(d[i]);
        if (b[k,d[i] mod p])and(k=i) then j:=0
       else if b[k,d[i] mod p] then begin d[i]:=0;j:=0 end
       else b[k,d[i] mod p]:=true;
       k:=t[k,d[i] mod p];
      until j=0;
    end;
    b[0,0]:=true;
    for i:=0 to n-1 do if d[i]=0 then b[0,0]:=false;
    if b[0,0] then find else write('No one knows.');
    end;
end;

begin{main}
  work;
end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator