标签:ring string ret next algo ace wrong pre div
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; int n,m,a[2005][2005],num; int head[500005],to[500005],next[500005]; bool used[500005],match[500005]; int ans; int dx[9]={0,2,2,1,1,-1,-1,-2,-2}; int dy[9]={0,1,-1,2,-2,2,-2,1,-1}; int id(int x,int y) { return (x-1)*m+y; } void make_way(int u,int v) { to[++num]=v; next[num]=head[u]; head[u]=num; } int dfs(int u) { int t; for(int edge=head[u];edge;edge=next[edge]) { int v=to[edge]; if(used[v]) continue; t=match[v]; match[v]=u; used[v]=1; if(!t||dfs(t)) return 1; match[v]=t; } return 0; } int main() { scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&a[i][j]); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(!a[i][j]&&(i+j)%2==1) { for(int dir=1;dir<=8;dir++) if(i+dx[dir]>=1&&i+dx[dir]<=n&&j+dy[dir]>=1&&j+dy[dir]<=m&&!a[i+dx[dir]][j+dy[dir]]) { make_way(id(i,j),id(i+dx[dir],j+dy[dir])); cout<<id(i,j)<<‘ ‘<<id(i+dx[dir],j+dy[dir])<<endl; } } int sum=0; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) if(!a[i][j]) { sum++; if((i+j)%2==1) { memset(used,0,sizeof(used)); if(dfs(id(i,j))) ans++; } } } cout<<match[6]<<endl; cout<<ans<<endl; printf("%d\n",sum-ans); }
标签:ring string ret next algo ace wrong pre div
原文地址:http://www.cnblogs.com/dancer16/p/7638615.html