还是道思路简单建图恶心的题

今天截图不能粘贴差评

 1 #include<bits/stdc++.h>
 2 #define inc(i,l,r) for(int i=l;i<=r;i++)
 3 #define dec(i,l,r) for(int i=l;i>=r;i--)
 4 #define link(x) for(edge *j=h[x];j;j=j->next)
 5 #define mem(a) memset(a,0,sizeof(a))
 6 #define inf 1e9
 7 #define ll long long
 8 #define succ(x) (1<<x)
 9 #define NM 1000
10 #define nm 100000
11 using namespace std;
12 int read(){
13     int x=0,f=1;char ch=getchar();
14     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
15     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
16     return x*f;
17 }
18 struct edge{
19     int t,v;
20     edge *next,*rev;
21 }e[nm],*h[NM],*o=e,*p[NM],*tmp[NM];
22 void _add(int x,int y,int v){
23     o->t=y;o->v=v;o->next=h[x];h[x]=o;o++;
24 }
25 void add(int x,int y,int v){
26     _add(x,y,v);_add(y,x,0);
27     h[x]->rev=h[y];h[y]->rev=h[x];
28 }
29 int n,m,tot,dis,b[25][25],ans,d[NM],cnt[NM];
30 char st[25];
31 int maxflow(){
32     int flow=0;edge *j;
33     inc(i,1,n)tmp[i]=h[i];
34     cnt[0]=tot;
35     for(int x=0,s=inf;d[x]<tot;){
36         for(j=tmp[x];j;j=j->next)
37         if(j->v&&d[j->t]+1==d[x])break;
38         if(j){
39             s=min(s,j->v);tmp[x]=p[j->t]=j;
40             if((x=j->t)==n){
41                 for(;x;x=p[x]->rev->t){
42                     p[x]->v-=s;
43                     p[x]->rev->v+=s;
44                 }
45                 flow+=s;s=inf;
46             }
47         }else{
48             if(!--cnt[d[x]])break;
49             d[x]=tot;
50             link(x)
51             if(j->v&&d[j->t]+1<d[x]){
52                 d[x]=d[j->t]+1;
53                 tmp[x]=j;
54             }
55             cnt[d[x]]++;
56             if(x)x=p[x]->rev->t;
57         }
58     }
59     return flow;
60 }
61 int main(){
62 //    freopen("data.in","r",stdin);
63     n=read();m=read();dis=read();
64     inc(i,1,n){
65         scanf("%s",st);
66         inc(j,1,m)
67             if(st[j-1]>'0'){
68                 b[i][j]=++tot;add(b[i][j],b[i][j]+1,st[j-1]-'0');tot++;
69             }
70     }
71     inc(i,1,n)
72     inc(j,1,m)
73     if(b[i][j])
74     inc(k,1,n)
75     inc(v,1,m)
76     if(!(i==k&&j==v)&&b[k][v]&&((i-k)*(i-k)+(j-v)*(j-v))<=(dis*dis)){
77         add(b[i][j]+1,b[k][v],inf);
78     }
79     inc(i,1,n){
80         scanf("%s",st);
81         inc(j,1,m)
82         if(st[j-1]=='L')
83         add(0,b[i][j],1),ans++;
84         inc(j,1,m)
85         if((b[i][j])&&(i<=dis||j<=dis||n-i<dis||m-j<dis))
86         add(b[i][j]+1,tot+1,inf);
87     }
88     n=tot+1;tot=n+1;
89     printf("%d\n",ans-maxflow());
90     return 0;
91 }
View Code

 

posted on 2016-01-03 01:33  onlyRP  阅读(183)  评论(0编辑  收藏  举报