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

求助:为何一直Wa

Posted by zhanglexingzlx at 2015-07-17 14:47:35 on Problem 3349
var i,j,k,n:longint;
    flag:boolean;
    hash:array[0..1000000] of longint;
    l:array[0..1000001] of longint;
    a:array[0..1000001,0..7] of longint;
 procedure sort(l,r,t:longint);
      var
         i,j,x,y:longint;
      begin
         i:=l;
         j:=r;
         x:=a[t,(l+r) div 2];
         repeat
           while a[t,i]<x do
            inc(i);
           while x<a[t,j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[t,i];
                a[t,i]:=a[t,j];
                a[t,j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j,t);
         if i<r then
           sort(i,r,t);
      end;

function pd:boolean;
var ii,x:longint;
    f:boolean;
begin
ii:=hash[k];
while ii<>0 do
      begin
      sort(1,6,i);
      sort(1,6,ii);
      f:=true;
      for x:=1 to 6 do
          if a[i,x]<>a[ii,x] then
             begin
             f:=false;
             break;
             end;
      if f then
         exit(true);
      ii:=l[ii];
      end;
pd:=false;
end;
begin
while not eof do
      begin
      readln(n);
      flag:=false;
      fillchar(hash,sizeof(hash),0);
      for i:=1 to n do
          begin
          k:=0;
          for j:=1 to 6 do
              begin
              read(a[i,j]);
              k:=(k+a[i,j]) mod 999983;
              end;
          k:=k mod 999983;
          if hash[k]=0
             then hash[k]:=i
             else begin
                  if pd
                     then begin
                          writeln('Twin snowflakes found.');
                          for j:=i to n do
                              readln;
                          flag:=true;
                          break;
                          end
                     else begin
                          l[i]:=hash[k];
                          hash[k]:=i;
                          end;
                  end;
          end;
      if flag=false then
         writeln('No two snowflakes are alike.');
      end;
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