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

1426 pascal 答案

Posted by BlackSdragonPking at 2015-07-31 19:52:16 on Problem 1426
var
  n:longint;
  f:array[0..300] of longint;
  q:array[0..100000] of longint;

procedure exo(king:longint);
begin
  if f[king]=0 then
    begin
      write(1); exit;
    end;
  exo(f[king]);
  if f[king]*10 mod n=king then write(0) else write(1);
end;



procedure bfs();
var i,king,s,r,l:longint;
begin
  fillchar(f,sizeof(f),255); f[1]:=0;
  l:=0; r:=1; q[r]:=1;
  while l<r do
    begin
      inc(l); s:=q[l];
      for i:=0 to 1 do
        begin
          king:=(s*10+i) mod n;
          if f[king]>=0 then continue;
          f[king]:=s;
          if king=0 then exit;
          inc(r); q[r]:=king;
        end;
    end;
end;




begin
 // assign(input,'multi.in'); reset(input);
 // assign(output,'multi.out'); rewrite(output);
  readln(n);
  while n>0 do
    begin
      if n=1 then writeln(1)
      else begin
             bfs(); exo(0); writeln;
           end;
      readln(n);
   end;
  //close(input);  close(output);
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