标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2905 Accepted Submission(s):
1702
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 using namespace std; 6 7 int vis[110],Map[110][110],n,m; 8 int ok[110]; 9 10 bool Find(int x) 11 { 12 for (int i=1; i<=n; i++) 13 { 14 if (Map[x][i]==1&&!vis[i]) 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; 27 return true; 28 } 29 } 30 } 31 } 32 return false; 33 } 34 35 int main() 36 { 37 int k,x,y,ans,flag=1; 38 while (~scanf("%d%d%d",&n,&m,&k)) 39 { 40 ans=0; 41 memset(Map,0,sizeof(Map)); 42 /* for (int i=1;i<=n;i++) 43 { 44 for (int j=1;j<=m;j++) 45 { 46 Map[i][j]=1; 47 } 48 }*/ 49 memset(ok,0,sizeof(ok)); 50 while (k--) 51 { 52 scanf("%d%d",&x,&y); 53 Map[x][y]=1; 54 } 55 for (int i=1; i<=m; i++) 56 { 57 memset(vis,0,sizeof(vis)); 58 if (Find(i)==true) 59 { 60 ans++; 61 } 62 } 63 int sum=0; 64 for (int i=1; i<=n; i++) 65 { 66 for (int j=1; j<=m; j++) 67 { 68 if (Map[i][j]==1) 69 { 70 memset(ok,0,sizeof(ok)); 71 int kk=0; 72 Map[i][j]=0; 73 for (int k=1; k<=m; k++) 74 { 75 memset(vis,0,sizeof(vis)); 76 if (Find(k)==true) 77 { 78 kk++; 79 } 80 } 81 if (kk<ans) 82 sum++; 83 Map[i][j]=1; 84 } 85 } 86 } 87 printf ("Board %d have %d important blanks for %d chessmen.\n",flag++,sum,ans); 88 } 89 return 0; 90 }
标签:
原文地址:http://www.cnblogs.com/qq-star/p/4674711.html