题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13500 Accepted Submission(s): 5913
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 using namespace std; 6 7 int Map[510][510],vis[510],n,m; 8 int ok[510];//ok表示的是被那个人占领 9 10 bool Find(int x) 11 { 12 for (int i=1; i<=n; i++) //扫描每一个男生 13 { 14 if(Map[x][i]==1&&!vis[i])//这里的vis的是避免出现死循环 15 { 16 vis[i]=1; 17 if (!ok[i])//没有被占领 18 { 19 ok[i]=x; 20 return true; 21 } 22 else 23 { 24 if (Find(ok[i])==true)//已经被占领,在帮其找一个看是否找的到 25 { 26 ok[i]=x;//如果可以帮其找到,把这个让给x 27 return true; 28 } 29 30 } 31 } 32 } 33 return false; 34 } 35 36 int main() 37 { 38 int k,ans,a,b; 39 while (~scanf("%d",&k)) 40 { 41 if (k==0) 42 break; 43 scanf("%d%d",&m,&n); 44 ans=0; 45 memset(Map,0,sizeof(Map)); 46 memset(ok,0,sizeof(ok)); 47 for (int i=1; i<=k; i++) 48 { 49 scanf("%d%d",&a,&b); 50 Map[a][b]=1; 51 } 52 for (int i=1; i<=m; i++) 53 { 54 memset(vis,0,sizeof(vis)); 55 if (Find(i)==true) 56 { 57 ans++; 58 } 59 } 60 printf ("%d\n",ans); 61 } 62 return 0; 63 }