hdu 1054 Strategic Game
来源:互联网 发布:淘宝刷手机单流程视频 编辑:程序博客网 时间:2024/06/05 02:19
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1054
简单二分匹配,根据题意构造一个无向图。然后求最小点覆盖,然后扫描mark数组将曾经匹配的点所匹配的边消去。
最小点覆盖 = 最大二分匹配
#include<stdio.h>#include<string.h>#define maxn 1505struct node{int v;node *next;}*head[maxn],edge[maxn*maxn],*p;int n,vis[maxn],mark[maxn];bool dfs(int v){for(node *p = head[v]; p ; p = p->next){if(vis[p->v])continue;vis[p->v] = 1;if(mark[p->v] == -1 || dfs(mark[p->v])){mark[p->v] = v;return true;}}return false;}int main(){int num,v,u,i,j;while(scanf("%d",&n) != EOF){memset(head,NULL,sizeof(head));p = edge;for(i = 0; i < n; i++){scanf("%d:(%d)",&u,&num);for(j = 0; j < num; j++){scanf("%d",&v);p->v = v;p->next = head[u];head[u] = p++;p->v = u;p->next = head[v];head[v] = p++;}}memset(mark,-1,sizeof(mark));int ans = 0;for(i = 0; i < n; i++){memset(vis,0,sizeof(vis));if(dfs(i))ans++;}//减去已有的边。。。for(i = 0; i < n; i++){if(mark[i] != -1){for(j = i+1; j < n; j++)if(mark[j] == i){mark[j] = -1;ans--;}}}printf("%d\n",ans);}return 0;}
- hdu 1054 Strategic Game
- HDU 1054 Strategic Game
- hdu 1054 Strategic Game
- hdu 1054 Strategic Game
- Hdu 1054 Strategic Game
- hdu 1054 Strategic Game
- HDU - 1054 Strategic Game
- hdu 1054 Strategic Game
- hdu-1054-Strategic Game
- HDU 1054 Strategic Game
- HDU 1054 Strategic Game
- HDU 1054 Strategic Game
- HDU 1054:Strategic Game
- HDU 1054 Strategic Game
- HDU 1054 Strategic Game
- HDU 1054Strategic Game 贪心
- hdu/hdoj 1054 Strategic Game
- hdu 1054 Strategic Game (二分匹配)
- dr.close()的用途(必要性)—”已有打开的与此命令相关联的 DataReader,必须首先将它关闭。"
- DuplicateHandle
- money system
- 网络视频下载利器Free YouTube Downloader Plus
- Hibernate基本知识(三)
- hdu 1054 Strategic Game
- 10071 - Back to High School Physics
- GA的使用方法,及注意的地方
- 10300 - Ecological Premium
- 如何安装LINUX虚拟机
- 依赖、关联、聚合和组合之间区别的理解
- Android模拟器命令详解
- 图片延迟加载实现 (改良版本)
- 458 - The Decoder