zoukankan      html  css  js  c++  java
  • 「BZOJ1066」[SCOI2007]蜥蜴

     1 #include<bits/stdc++.h>
     2 #define myp pair<int,int>
     3 #define mp make_pair
     4 using namespace std;
     5 const int N=30,N2=900,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1},oo=2e9;
     6 int n,m,d,tot,super_s,super_t,h[N][N],sum;
     7 inline int getid(int a,int b){return (a-1)*m+b;}
     8 inline int getdis(int x1,int y1,int x2,int y2){return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);}
     9 struct Edge{
    10     int from,to,flow,cap;
    11     Edge(int _from=0,int _to=0,int _flow=0,int _cap=0):from(_from),to(_to),flow(_flow),cap(_cap){}
    12 };
    13 vector<Edge>edge;
    14 vector<int>point[N2];
    15 int edge_tot;
    16 void add_edge(int f,int t,int c){
    17 //  cout<<f<<" "<<t<<" "<<c<<endl;
    18     edge.push_back(Edge(f,t,0,c));
    19     point[f].push_back(edge_tot++);
    20     edge.push_back(Edge(t,f,0,0));
    21     point[t].push_back(edge_tot++);
    22     return;
    23 }
    24 int dis[N][N];
    25 int level[N2];
    26 bool d_bfs(){
    27     memset(level,0,sizeof(level));
    28     queue<int>q;
    29     int x;
    30     q.push(super_s);
    31     level[super_s]=1;
    32     while(!q.empty()){
    33         x=q.front();q.pop();
    34         for(int i=0;i<point[x].size();i++){
    35             if(edge[point[x][i]].cap<=edge[point[x][i]].flow) continue;
    36             if(!level[edge[point[x][i]].to]){
    37                 level[edge[point[x][i]].to]=level[x]+1;
    38                 q.push(edge[point[x][i]].to);
    39             }
    40         }
    41     }
    42     return level[super_t];
    43 }
    44 int dfs(int k,int a){
    45     if(!a||k==super_t) return a;
    46     int ans=0,temp,x;
    47     for(int i=0;i<point[k].size();i++){
    48         Edge& e=edge[point[k][i]];
    49         x=edge[point[k][i]].to;
    50         if(level[x]==level[k]+1&&edge[point[k][i]].cap>edge[point[k][i]].flow&&(temp=dfs(x,min(a,edge[point[k][i]].cap-edge[point[k][i]].flow)))){
    51             ans+=temp,a-=temp;
    52             edge[point[k][i]].flow+=temp,edge[point[k][i]^1].flow-=temp;
    53             if(!a) return ans;
    54         }
    55     }
    56     return ans;
    57 }
    58 int dinic(){
    59     int ans=0;
    60     while(d_bfs()) ans+=dfs(super_s,oo);
    61     return ans;
    62 }
    63 int main(){
    64     int t1;
    65     char c[30];
    66     scanf("%d%d%d",&n,&m,&d);
    67     tot=n*m,super_s=tot+tot+1,super_t=super_s+1;
    68     for(int i=1;i<=n;i++){
    69         scanf("%s",&c);
    70         for(int j=1;j<=m;j++){
    71             h[i][j]=c[j-1]-'0';
    72             if(h[i][j]){t1=getid(i,j);add_edge(t1,t1+tot,h[i][j]);}
    73         }
    74     }
    75     for(int i=1;i<=n;i++)
    76         for(int j=1;j<=m;j++) if(h[i][j]){
    77             if(i<d+1||j<d+1||i+d>n||j+d>m) add_edge(getid(i,j)+tot,super_t,oo);
    78             for(int ii=1;ii<=n;ii++)
    79                 for(int jj=1;jj<=m;jj++)if(h[ii][jj]&&getdis(i,j,ii,jj)<=d*d) add_edge(getid(i,j)+tot,getid(ii,jj),oo);
    80         }
    81     for(int i=1;i<=n;i++){
    82         scanf("%s",&c);
    83         for(int j=1;j<=m;j++){
    84             if(c[j-1]=='L'){
    85                 add_edge(super_s,getid(i,j),1);
    86                 sum++;
    87             }
    88         }
    89     }
    90     printf("%d
    ",sum-dinic());
    91     return 0;
    92 }
  • 相关阅读:
    存储过程调用API
    Visual Studio 2019 添加不了区域 解决办法
    .NET Core 3.1 IIS其它网站出现HTTP503无法访问解决方法
    串口数据处理分包处理
    树莓派实践总和
    mysql定期任务
    Newtonsoft.Json.Linq 序列化 反序列化等知识
    使用IDbCommandInterceptor解决EF-CORE-3.x-使用MYSQL时,未正常的生成LIKE查询语句
    .Net Core自定义读取配置文件信息appsettings.Json
    .Net Core Cors跨域
  • 原文地址:https://www.cnblogs.com/mycups/p/8527872.html
Copyright © 2011-2022 走看看