匀贵网站建设,wordpress 国内主题 营销主题,dw做的网站如何使用,西安做北郊做网站正题
题目链接:https://www.luogu.com.cn/problem/P2472 题目大意 n∗mn*mn∗m个格子#xff0c;每个格子的石柱高度不同#xff0c;蜥蜴可以跳到距离不超过ddd的石柱处#xff0c;并且先前所站的石柱高度减一#xff0c;为0则不能站#xff0c;然后求有多少只蜥蜴不可以…正题
题目链接:https://www.luogu.com.cn/problem/P2472 题目大意
n∗mn*mn∗m个格子每个格子的石柱高度不同蜥蜴可以跳到距离不超过ddd的石柱处并且先前所站的石柱高度减一为0则不能站然后求有多少只蜥蜴不可以逃脱。 解题思路
考虑网络流每只蜥蜴表示一个流将每个石柱分成入点和出点然后入点连出点流量为石柱高度然后每个可以走的点之间出点连入点无限之后有蜥蜴的柱子原点连入点流量为1可以逃脱的出点连汇点。
然后dinic即可。 codecodecode
#includecstdio
#includecstring
#includealgorithm
#includequeue
#define p(x,y,w) ((((x)-1)*m(y))*2-w)
using namespace std;
const int N1e510,M4e510,inf2147483647/3;
struct node{int to,next,w;
}a[M];
int n,m,tot1,s,t,d,ans;
int ls[N],dep[N];
char str[30];
queueint q;
void addl(int x,int y,int w){a[tot].toy;a[tot].nextls[x];ls[x]tot;a[tot].ww;a[tot].tox;a[tot].nextls[y];ls[y]tot;a[tot].w0;return;
}
int dis(int x1,int y1,int x2,int y2)
{return (x2-x1)*(x2-x1)(y2-y1)*(y2-y1);}
void connect(int x,int y){for(int i1;in;i)for(int j1;jm;j)if(dis(x,y,i,j)d*d(i!x||j!y))addl(p(x,y,1),p(i,j,0),inf);return;
}
bool bfs(){memset(dep,0,sizeof(dep));while(!q.empty())q.pop();q.push(s);dep[s]1;while(!q.empty()){int xq.front();q.pop();for(int ils[x];i;ia[i].next){int ya[i].to;if(!a[i].w||dep[y])continue;dep[y]dep[x]1;if(yt)return 1;q.push(y);}}return 0;
}
int dinic(int x,int flow){int rest0,k;if(xt)return flow;for(int ils[x];i;ia[i].next){int ya[i].to;if(!a[i].w||dep[y]!dep[x]1)continue;rest(kdinic(y,min(flow-rest,a[i].w)));a[i].w-k;a[i^1].wk;if(restflow)return flow;}if(!rest)dep[x]0;return rest;
}
void net_work(){while(bfs())ans-dinic(s,inf);
}
int main()
{scanf(%d%d%d,n,m,d);sp(n,m,0)1;ts1;for(int i1;in;i){scanf(%s,str1);for(int j1;jm;j){addl(p(i,j,0),p(i,j,1),str[j]-0);connect(i,j);}}for(int i1;in;i){scanf(%s,str1);for(int j1;jm;j){if(str[j]L)addl(s,p(i,j,0),1),ans;if(id||jd||n-id||m-jd)addl(p(i,j,1),t,inf);}}net_work();printf(%d,ans);
}