Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
竟然忘了初始化了,贴代码#include<iostream> #include<cstdio> #include<string.h> using namespace std; int n,m,p,i,j,x,y,ans,t,r[1000],a[1000][1000]; bool b[1000],map[1000][1000],g[1000]; char ch; bool dfs(int k) { g[k]=1; for(int j=1;j<=n;++j) if(map[k][j]) { if(!b[j]) { b[j]=1; r[j]=k; return 1; } if(!g[r[j]]&&dfs(r[j])) { b[j]=1; r[j]=k; return 1; } } return 0; } int main() { cin>>t; for(p=1;p<=t;++p) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(map,0,sizeof(map)); ans=0; n=0; cin>>x>>y; for(i=1;i<=x;++i) for(j=1;j<=y;++j) { cin>>ch; if(ch=='*') { n++; a[i][j]=n; } } for(i=1;i<=x;++i) for(j=1;j<=y;++j) { if(a[i][j-1]>0)map[a[i][j]][a[i][j-1]]=1; if(a[i][j+1]>0)map[a[i][j]][a[i][j+1]]=1; if(a[i-1][j]>0)map[a[i][j]][a[i-1][j]]=1; if(a[i+1][j]>0)map[a[i][j]][a[i+1][j]]=1; } for(i=1;i<=n;++i) { memset(g,0,sizeof(g)); if(dfs(i))ans++; } ans=n-ans/2; cout<<ans<<endl; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator