标签:time input 象棋 int etc boa rip div ted
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5277 Accepted Submission(s): 3120
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define N 1500+10 using namespace std; bool vis[N]; int n,m,k,x,y,girl[N],map[N][N]; int read() { int x=0,f=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1; ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘; ch=getchar();} return x*f; } int find(int x) { for(int i=1;i<=m;i++) { if(!vis[i]&&map[x][i]) { vis[i]=true; if(girl[i]==-1||find(girl[i])) {girl[i]=x;return 1;} } } return 0; } int col() { int s=0;memset(girl,-1,sizeof(girl)); for(int i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(find(i)) s++; } return s; } int main() { int t=0,sum,ans; while(scanf("%d%d%d",&n,&m,&k)!=EOF) { ans=0,sum=0; memset(map,0,sizeof(map)); for(int i=1;i<=k;i++) x=read(),y=read(),map[x][y]=1; ans=col(); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(map[i][j]==1) { map[i][j]=0; if(col()<ans) sum++; map[i][j]=1; } printf("Board %d have %d important blanks for %d chessmen.\n",++t,sum,ans); } return 0; }
标签:time input 象棋 int etc boa rip div ted
原文地址:http://www.cnblogs.com/z360/p/7433781.html