标签:程序设计 possible source mission chosen orb print return grid
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2683 Accepted Submission(s): 1538
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define N 110 using namespace std; bool vis[N],vist[N]; int n,k,sum,tot,ans[N],girl[N],a[N][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<=n;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; } void begin() { sum=0,tot=0; memset(a,0,sizeof(a)); memset(ans,0,sizeof(ans)); memset(vist,0,sizeof(vist)); } int main() { while(1) { n=read(),k=read(); if(n==0&&k==0) break; begin(); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) a[i][j]=read(); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(!vist[a[i][j]]) { vist[a[i][j]]=true; memset(map,0,sizeof(map)); for(int u=1;u<=n;u++) for(int v=1;v<=n;v++) if(a[u][v]==a[i][j]) map[u][v]=1; if(col()>k) ans[++sum]=a[i][j]; } if(sum==0) {printf("-1\n"); continue;} sort(ans+1,ans+1+sum); for(int i=1;i<sum;i++) printf("%d ",ans[i]); printf("%d\n",ans[sum]); } return 0; }
标签:程序设计 possible source mission chosen orb print return grid
原文地址:http://www.cnblogs.com/z360/p/7434416.html