意甲冠军:

它需要一个特殊的图,以找到最大匹配。该图的特征是:无向图,度的每个节点3。这是一个双边连接组件(the graph is 2-edge-connected (that is, at least 2 edges need to be removed in order to make the graph disconnected) 这一点是这样理解的把。。)

思路:

一般想法就直接建图求最大匹配,点的范围是5000,不优化可能超时,以下代码是890ms过的。

还有一种思路:

完备匹配的条件:

1. G是K(K>0)次正则二分图

2.G是无桥的三次正则图

3.G在去掉随意一个顶点子集S后,其子图中含顶点数为奇数的连通分支数不大于|S|

具有以上三个特征的图一定有完备匹配。且当中第三点是完备匹配的充要条件。

据此可得。题目中所给的图一定是完备匹配。答案是n/2。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
const int maxn=5010;
using namespace std; int main()
{
int n,a,b,t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<3*n/2;i++)
scanf("%d%d",&a,&b);
printf("%d\n",n/2);
}
return 0;
}
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
const int maxn=5010;
using namespace std; int mx[maxn],my[maxn],n;
bool vis[maxn];
vector<int> e[maxn]; int path(int i)
{
int j,sz=e[i].size();
for(j=0;j<sz;j++)
{
int tmp=e[i][j];
if(!vis[tmp])
{
vis[tmp]=1;
if(my[tmp]==-1||path(my[tmp]))
{
my[tmp]=i;
mx[i]=tmp;
return 1;
}
}
}
return 0;
} int hungary()
{
int res=0;
memset(mx,-1,(n+2)*sizeof(int));
memset(my,-1,(n+2)*sizeof(int));
for(int i=1;i<=n;i++)
{
if(mx[i]==-1)
{
memset(vis,0,(n+2)*sizeof(vis[0]));
res+=path(i);
}
}
return res;
} int main()
{
int T,m,a,b,i;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
m=3*n/2;
for(i=1;i<=n;i++)
e[i].clear();
while(m--)
{
scanf("%d%d",&a,&b);
e[a].push_back(b);
e[b].push_back(a);
}
printf("%d\n",hungary()/2);
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

hdu1845 Jimmy’s Assignment --- 完整匹配的更多相关文章

  1. HDU 1845 Jimmy’s Assignment(二分匹配)

    Jimmy’s Assignment Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Other ...

  2. Makefile:(实验)多个目标匹配时会采用最完整匹配的目标

    结论源自实验测试,如果有疏漏希望指出 当Makefile中存在多个匹配的目标时,Makefile会采用哪个匹配的目标呢? 测试的Makefile如下: .PHONY: all clean quick_ ...

  3. HDU - 1845 Jimmy’s Assignment (二分匹配)

    Description Jimmy is studying Advanced Graph Algorithms at his university. His most recent assignmen ...

  4. Poj 3189 Steady Cow Assignment (多重匹配)

    题目链接: Poj 3189 Steady Cow Assignment 题目描述: 有n头奶牛,m个棚,每个奶牛对每个棚都有一个喜爱程度.当然啦,棚子也是有脾气的,并不是奶牛想住进来就住进来,超出棚 ...

  5. CodeFroces New Assignment 二分图匹配

    There is a class consisting of n students, in which each one has a number representing his/her perso ...

  6. hdu2853 Assignment 完美匹配 多校联赛的好题

    PS:好题.不看题解绝对AC不了. 题解来源: http://blog.csdn.net/niushuai666/article/details/7176290 http://www.cnblogs. ...

  7. PHP正则匹配title标题文本

    //////////////////////////////////////////////////////////////////////////////////////////////////// ...

  8. 使用正则表达式匹配HTML 下各种<title>标签

    http://www.oschina.net/question/195686_46313 <title>标题</title> <title>标题</title ...

  9. 正则匹配<img src="xxxxxx" alt="" />标签的相关写法

    1.(<img\ssrc[^>]*>) 2.content.replace(/<img [^>]*src=['"]([^'"]+)[^>]*&g ...

随机推荐

  1. 【】maze

    [链接]点击打开链接 [题意] 小 T 被放到了一个迷宫之中,这个迷宫由 n 个节点构成,两个节点之间可能存在多条无 向边,小 T 的起点为 1 号节点,终点为 n 号节点.有 m 条无向边,对于每一 ...

  2. UML学习总结(1)——UML学习入门

    随着亲手接触的项目越来越多,项目的复杂度越来越大,项目的理解程度也变的很难,尤其是在接收一个别人已经做好的项目时,你迫切先想到的就是"有没有文档啊",当然是各种文档,概要设计文档, ...

  3. apache-spark导入eclipse环境

    工作中用到了apache-spark,想深入了解一下,决定从源码开始. 先导入到常用的ide,eclipse吧: 准备工作 1.  下载Eclipse:http://scala-ide.org/ 2. ...

  4. Virtualizing physical memory in a virtual machine system

    A processor including a virtualization system of the processor with a memory virtualization support ...

  5. centos中的配置文件 分类: B3_LINUX 2015-04-03 22:21 184人阅读 评论(0) 收藏

    /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置. /etc/bashrc:为每一个 ...

  6. php课程 8-28 php如何绘制生成显示图片

    php课程 8-28 php如何绘制生成显示图片 一.总结 一句话总结:gd库轻松解决 1.php图片操作生成的图的两种去向是什么? 一种在页面直接输出,一种存进本地磁盘 2.php操作图片的库有哪些 ...

  7. 基于PHP实现一个简单的在线聊天功能(轮询ajax )

    基于PHP实现一个简单的在线聊天功能(轮询ajax ) 一.总结 1.用的轮询ajax 二.基于PHP实现一个简单的在线聊天功能 一直很想试着做一做这个有意思的功能,感觉复杂的不是数据交互和表结构,麻 ...

  8. PHP通用非法字符检测函数集锦

    <? // [变量定义规则]:‘C_’=字符型,‘I_’=整型,‘N_’=数字型,‘L_’=布尔型,‘A_’=数组型 // ※CheckMoney($C_Money) 检查数据是否是 99999 ...

  9. C++利用SOAP开发WebService

    // soapconsole.cpp : Defines the entry point for the console application.// #include "stdafx.h& ...

  10. Range锁(也即范围锁)

    浅析SQL Server在可序列化隔离级别下,防止幻读的范围锁的锁定问题 本文出处:http://www.cnblogs.com/wy123/p/7501261.html (保留出处并非什么原创作品权 ...