【NOIP2016提高A组模拟9.14】灌水

【NOIP2016提高A组模拟9.14】灌水_第1张图片

输入
第一行n,m
后面有一个一个数出现的为询问数q
Sample Input

1 2
01
4
0 0
2 0
0 1
0 2

Sample Output

0.7854
4.8584
0.0000
4.8584

比赛时の想法

分情况讨论,每一次有一个询问的点我们就把它可以到达的不在隔板上的点dfs出来,然后再随便讨论一下就好了
感觉自己好随意啊

贴代码

var
    a,b:array[-1..305,-1..305]of longint;
    bz,bz1:array[-1..205,-1..205]of boolean;
    s:array[0..40005,1..2]of longint;
    h:array[1..8,1..2]of longint=((-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1));
    g:array[1..2,1..2]of longint=((1,-1),(1,1));
    nc:array[1..4,1..2]of longint=((-1,-1),(-1,0),(0,-1),(0,0));
    i,j,k,l,n,m,t1,t2,q,z,zz,o:longint;
    ans:extended;
    x:char;
procedure dfs(t1,t2:longint);
var
    i,x,y:longint;
begin
    for i:=1 to 8 do
    begin
        x:=t1+h[i,1];
        y:=t2+h[i,2];
        if (x<0) or (y<0) or (x>n*2) or (y>m*2) then continue;
        if bz[x,y]=true then continue;
        if (xand (yand (b[t1-1,t2-1]>0) then continue;
        if (xand (y>t2) and (b[t1-1,t2]>0) then continue;
        if (x>t1) and (yand (b[t1,t2-1]>0) then continue;
        if (x>t1) and (y>t2) and (b[t1,t2]>0) then continue;
        inc(z);
        s[z,1]:=x;
        s[z,2]:=y;
        bz[x,y]:=true;
        dfs(x,y);
    end;
end;
begin
   // assign(input,'t2.in'); reset(input);
    readln(n,m);
    for i:=1 to n do
    begin
        for j:=1 to m do
        begin
            read(x);
            t1:=(i-1)*2;
            t2:=(j-1)*2;
            bz1[t1+1,t2]:=true;
            bz1[t1,t2+1]:=true;
            bz1[t1+1,t2+2]:=true;
            bz1[t1+2,t2+1]:=true;
            if x='0' then
            begin
                b[t1,t2]:=1;
                b[t1+1,t2+1]:=2;
            end else
            begin
                b[t1,t2+1]:=3;
                b[t1+1,t2]:=4;
            end;
        end;
        readln;
    end;
    readln(q);
    for o:=1 to q do
    begin
        readln(t1,t2);
        bz:=bz1;
        if bz1[t1,t2]=true then
        begin
            writeln('0.0000');
            continue;
        end;
        bz[t1,t2]:=true;
        z:=1;
        s[z,1]:=t1;
        s[z,2]:=t2;
        dfs(t1,t2);
        fillchar(bz,sizeof(bz),0);
        zz:=z;
        for i:=1 to z do
            bz[s[i,1],s[i,2]]:=true;
        ans:=0;
        for i:=1 to z do
        begin
            for j:=1 to 2 do
                if bz[s[i,1]+g[j,1],s[i,2]+g[j,2]]=true then ans:=ans+1;
            for j:=1 to 4 do
            begin
                t1:=s[i,1]+nc[j,1];
                t2:=s[i,2]+nc[j,2];
                if (t1<0) or (t2<0) or (t1>n*2) or (t2>m*2) then continue;
                if (j=1) and (b[t1,t2]=1) then ans:=ans+1-0.25*pi else
                if (j=1) and (b[t1,t2]=2) then ans:=ans+0.25*pi else
                if (j=2) and (b[t1,t2]=3) then ans:=ans+1-0.25*pi else
                if (j=2) and (b[t1,t2]=4) then ans:=ans+0.25*pi else
                if (j=3) and (b[t1,t2]=3) then ans:=ans+0.25*pi else
                if (j=3) and (b[t1,t2]=4) then ans:=ans+1-0.25*pi else
                if (j=4) and (b[t1,t2]=1) then ans:=ans+0.25*pi else
                if (j=4) and (b[t1,t2]=2) then ans:=ans+1-0.25*pi;
            end;
        end;
        writeln(ans:0:4);
    end;
  //  close(input);
end.

你可能感兴趣的:(模拟)