【bzoj1066】[SCOI2007]蜥蜴

来源:互联网 发布:无3c被淘宝下架了宝贝 编辑:程序博客网 时间:2024/04/29 19:41

[SCOI2007]蜥蜴

Description

  在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃
到边界外。 每行每列中相邻石柱的距离为1,蜥蜴的跳跃距离是d,即蜥蜴可以跳到平面距离不超过d的任何一个石
柱上。石柱都不稳定,每次当蜥蜴跳跃时,所离开的石柱高度减1(如果仍然落在地图内部,则到达的石柱高度不
变),如果该石柱原来高度为1,则蜥蜴离开后消失。以后其他蜥蜴不能落脚。任何时刻不能有两只蜥蜴在同一个
石柱上。

Input

  输入第一行为三个整数r,c,d,即地图的规模与最大跳跃距离。以下r行为石竹的初始状态,0表示没有石柱
,1~3表示石柱的初始高度。以下r行为蜥蜴位置,“L”表示蜥蜴,“.”表示没有蜥蜴。

Output

  输出仅一行,包含一个整数,即无法逃离的蜥蜴总数的最小值。

Sample Input

5 8 2

00000000

02000000

00321100

02000000

00000000

……..

……..

..LLLL..

……..

……..
Sample Output

1
HINT

100%的数据满足:1<=r, c<=20, 1<=d<=4

可以用爆搜骗3个点,正解就是——网络流。

#include<cmath>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;struct node{    int x,y,c,next,other;}a[1100000];int len,last[1100000];int st,ed;int n,m,d;void ins(int x,int y,int c){    int k1,k2;    len++;k1=len;    a[len].x=x;a[len].y=y;a[len].c=c;    a[len].next=last[x];last[x]=len;    len++;k2=len;    a[len].x=y;a[len].y=x;a[len].c=0;    a[len].next=last[y];last[y]=len;    a[k1].other=k2;    a[k2].other=k1; }int list[1100000],h[1100000],head,tail;bool bt_h(){    memset(h,0,sizeof(h));h[st]=1;    list[1]=st;    head=1,tail=2;    while(head!=tail)    {        int x=list[head];        for(int k=last[x];k;k=a[k].next)        {            int y=a[k].y;            if(h[y]==0&&a[k].c>0)            {                h[y]=h[x]+1;                list[tail++]=y;            }        }        head++;    }    if(h[ed]>0) return true;    else return false;}int findflow(int x,int f){    if(x==ed) return f;    int s=0,t;    for(int k=last[x];k;k=a[k].next)    {        int y=a[k].y;        if(h[y]==(h[x]+1)&&a[k].c>0&&f>s)        {            t=findflow(y,min(a[k].c,f-s));            s+=t;            a[k].c-=t;a[a[k].other].c+=t;        }    }    if(s==0) h[x]=0;    return s;}double check(int x,int y,int x1,int y1){    return sqrt(double((x-x1)*(x-x1)+(y-y1)*(y-y1)));}int x[1100][1100],ans,maxx,xx[1100][1100],v[1100][1100];int main(){    scanf("%d%d%d",&n,&m,&d);    st=0;ed=n*m*2+1;    len=0;memset(last,0,sizeof(last));    for(int i=1;i<=n;i++)    {        char s[1100];scanf("%s",s+1);        for(int j=1;j<=m;j++)        {            x[i][j]=s[j]-'0';            xx[i][j]=(m*(i-1)+j);            v[i][j]=xx[i][j]+n*m;            if(x[i][j]>0) ins(xx[i][j],v[i][j],x[i][j]);            if(i<=d||j<=d||i>=n-d+1||j>=m-d+1)            {                ins(v[i][j],ed,999999999);            }        }    }    maxx=0;    for(int i=1;i<=n;i++)    {        char s[1100];scanf("%s",s+1);        for(int j=1;j<=m;j++)        {            if(s[j]=='L')            {                maxx++;                ins(st,xx[i][j],1);            }        }    }    for(int i=1;i<=n;i++)    {        for(int j=1;j<=m;j++)        {            int x1,x2,x3,x4;            x1=max(i-d,1);x2=min(i+d,n);            x3=max(j-d,1);x4=min(j+d,m);            for(int x=x1;x<=x2;x++)            {                for(int y=x3;y<=x4;y++)                {                    if(check(i,j,x,y)<=d)                    {                        if((x!=i||y!=j))                        {                            ins(v[i][j],xx[x][y],999999999);                        }                    }                }            }        }    }    ans=0;    while(bt_h()==true)    {        ans+=findflow(st,999999999);    }    printf("%d\n",maxx-ans);    return 0;}
0 0
原创粉丝点击