标签:des style blog http color java os io
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2492 Accepted Submission(s): 1452
1 /*Problem : 1281 ( 棋盘游戏 ) Judge Status : Accepted 2 RunId : 11517709 Language : C++ Author : huifeidmeng 3 Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta*/ 4 5 #include<cstdio> 6 #include<cstring> 7 #include<cstdlib> 8 using namespace std; 9 const int maxn=105; 10 static int cont=1; 11 bool mat[maxn][maxn],vis[maxn]; 12 int chess[maxn]; 13 int n,m,k; 14 int match(int x){ 15 for(int i=1;i<=m;i++){ 16 if(mat[x][i]&&!vis[i]){ 17 vis[i]=1; 18 if(!chess[i]||match(chess[i])){ 19 chess[i]=x; 20 return 1; 21 } 22 } 23 } 24 return 0; 25 } 26 int a[maxn*maxn],b[maxn*maxn]; 27 int main(){ 28 //freopen("test.in","r",stdin); 29 while(scanf("%d%d%d",&n,&m,&k)!=EOF){ 30 memset(mat,0,sizeof(mat)); 31 memset(chess,0,sizeof(chess)); 32 for(int i=0;i<k;i++){ 33 scanf("%d%d",&a[i],&b[i]); 34 mat[a[i]][b[i]]=1; 35 } 36 int ans=0; 37 for(int i=1;i<=n;i++){ 38 memset(vis,0,sizeof(vis)); 39 ans+=match(i); 40 } 41 int res=0; //重要点个数 42 //判断一个点重不重要,去掉这个点看看对这个匹配有没有影响就行了 43 for(int i=0;i<k;i++){ 44 memset(chess,0,sizeof(chess)); 45 mat[a[i]][b[i]]=0; //拿掉那个点,再来一次匹配 46 int val=0; 47 for(int j=1;j<=n;j++){ 48 memset(vis,0,sizeof(vis)); 49 val+=match(j); 50 } 51 if(ans>val) res++; //说明有影响...是一个重要点 52 mat[a[i]][b[i]]=1; //将拿掉的那个点复原 53 } 54 printf("Board %d have %d important blanks for %d chessmen.\n",cont++,res,ans); 55 } 56 return 0; 57 }
hdu------1281 棋盘游戏(最小覆盖点),布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/gongxijun/p/3928694.html