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

ioi的题 就是恶心

Posted by dsqwwe at 2011-03-19 16:01:56 on Problem 1175
不会证明取值和这个哈希的正确性
就手工算了算8种变化的情况
program dsqwwe;
  type
    tt=array[0..100,0..100] of longint;
    ttt=record
      x,y:longint;
    end;
  var
    map,map1,a:tt;
    b:array[1..50] of tt;
    v:array[0..100,0..100] of boolean;
    n,m,i,j,ii,jj,st1,st2,ed1,ed2,t,sum,closed,open:longint;
    s:string;
    d:array[1..10000] of ttt;
  function pd(a,b:tt):boolean;
    var
      i,j:longint;
    begin
     for i:=1 to n do
      for j:=1 to m do
       if a[i,j]<>b[i,j] then exit(false);
     exit(true);
    end;
  procedure find(h,l:longint);
    const
      dx:array[1..8] of longint=(1,-1,0,0,1,1,-1,-1);
      dy:array[1..8] of longint=(0,0,-1,1,1,-1,1,-1);
    var
      x,y,xx,yy,i:longint;
    begin
      fillchar(d,sizeof(d),0);
      closed:=1;
      open:=1;
      d[1].x:=h; d[1].y:=l;
      st1:=h; st2:=l; ed1:=h; ed2:=l;
      v[h,l]:=true;
      while closed<=open do
       begin
         x:=d[closed].x;
         y:=d[closed].y;
         for i:=1 to 8 do
          begin
            xx:=x+dx[i];
            yy:=y+dy[i];
            if (not v[xx,yy]) and (xx>0) and (xx<=n) and (yy>0) and (yy<=m) and (a[xx,yy]<>0) then
              begin
                inc(open);
                d[open].x:=xx;
                d[open].y:=yy;
                v[xx,yy]:=true;
                if xx<st1 then st1:=xx;
                if xx>ed1 then ed1:=xx;
                if yy<st2 then st2:=yy;
                if yy>ed2 then ed2:=yy;
              end;
          end;
         inc(closed);
      end;
     for i:=1 to open do
      map[d[i].x-(st1-1),d[i].y-(st2-1)]:=1;
   end;
  function findd:longint;
    var
      nn,mm,i,j:longint;
    begin
      nn:=ed1-st1+1;
      mm:=ed2-st2+1;
      ///1/////////
      for i:=1 to sum do
       if pd(map,b[i]) then exit(i);
      ///2////////////
      fillchar(map1,sizeof(map1),0);
      for i:=1 to nn do
       for j:=1 to mm do
        map1[j,nn-i+1]:=map[i,j];
      for i:=1 to sum do
       if pd(map1,b[i]) then exit(i);
      ///3////////////
      fillchar(map1,sizeof(map1),0);
      for i:=1 to nn do
       for j:=1 to mm do
        map1[nn-i+1,mm-j+1]:=map[i,j];
      for i:=1 to sum do
       if pd(map1,b[i]) then exit(i);
      ///4///////////////
      fillchar(map1,sizeof(map1),0);
      for i:=1 to nn do
       for j:=1 to mm do
        map1[mm-j+1,i]:=map[i,j];
      for i:=1 to sum do
       if pd(map1,b[i]) then exit(i);
      ///5/////////////////
      fillchar(map1,sizeof(map1),0);
      for i:=1 to nn do
       for j:=1 to mm do
        map1[nn-i+1,j]:=map[i,j];
      for i:=1 to sum do
       if pd(map1,b[i]) then exit(i);
      ///6//////////////////
      fillchar(map1,sizeof(map1),0);
      for i:=1 to nn do
       for j:=1 to mm do
        map1[j,i]:=map[i,j];
      for i:=1 to sum do
       if pd(map1,b[i]) then exit(i);
     ///7///////////////////
      fillchar(map1,sizeof(map1),0);
      for i:=1 to nn do
       for j:=1 to mm do
        map1[i,mm-j+1]:=map[i,j];
      for i:=1 to sum do
       if pd(map1,b[i]) then exit(i);
     ///8///////////////////////
      fillchar(map1,sizeof(map1),0);
      for i:=1 to nn do
       for j:=1 to mm do
        map1[mm-j+1,nn-i+1]:=map[i,j];
      for i:=1 to sum do
       if pd(map1,b[i]) then exit(i);
      ////////
     inc(sum);
     b[sum]:=map;
     exit(sum);
    end;
  begin
    assign(input,'pku1175.in');
    reset(input);
    assign(output,'pku1175.out');
    rewrite(output);

    readln(m);
    readln(n);
    for i:=1 to n do
     begin
       readln(s);
       for j:=1 to m do
        a[i,j]:=ord(s[j])-ord('0');
     end;
    for i:=1 to n do
     for j:=1 to m do
      if (a[i,j]<>0) and (v[i,j]=false) then
       begin
         fillchar(map,sizeof(map),0);
         find(i,j);
         t:=findd;
        for ii:=1 to open do
         a[d[ii].x,d[ii].y]:=t;
       end;
    for i:=1 to n do
     begin
      for j:=1 to m do
       if a[i,j]=0 then write(0)
        else write(chr(a[i,j]+ord('a')-1));
      writeln;
     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