意甲冠军:

它需要一个特殊的图,以找到最大匹配。该图的特征是:无向图,度的每个节点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. jqgrid 实现行编辑,表单编辑的列联动

    这个问题的场景相信大家都遇到过,比方有A,B,C三列,B,C列均为下拉框.可是C列的值是由B列的值来决定的.即C列中的值是动态变化的,变化的根据就是B列中你选择的值. 本文给出的是一个有用,简易快捷的 ...

  2. Eclipse 出错 Error:Could not create the Java Virtual Machine Error:A fatal exception has occurred

    提示如下: scala compile server. error:could not create the java machine.Error: A fatal exception has occ ...

  3. XML Parser Errors See Details for more Information XML Parser Error on line 1: Document root ele

    1.错误描写叙述 XML Parser Errors See Details for more Information XML Parser Error on line 1: Document roo ...

  4. vue项目中一些文件的作用

    原文 简书原文:https://www.jianshu.com/p/38749e5bec3c 大纲 1.vue项目结构 2.主要的配置文件 2.1.package.json 2.2.dev-serve ...

  5. UVA 10106 Product (大数相乘)

    Product The Problem The problem is to multiply two integers X, Y. (0<=X,Y<10250) The Input The ...

  6. Linux有问必答:Linux上如何查看某个进程的线程

    原创:LCTT https://linux.cn/article-5633-1.html 译者: GOLinux本文地址:https://linux.cn/article-5633-1.html201 ...

  7. centos7 安装php环境和安装swoole

    这仅是我在网上找了多个解决方法,搞定了我遇到的问题,做的一个记录,买这个服务器就是为了测试swoole,结果快到期了,swoole还没装好 感谢https://www.cnblogs.com/phpw ...

  8. 使用Perl处理Excel之DMA映射

    使用Perl处理Excel之DMA映射 功能 通道处理,将各个通道的外设映射到通道上 外设ack信号处理 脚本执行情况 顶层Perl脚本(dma_parse.pl) 将上述两个功能脚本整合,便于调用 ...

  9. jquery formcheck.js

    demo下载链接http://pan.baidu.com/s/1hrDCC3y     /* Jquery 表单验证插件 janchie 2010.1 janchie@163.com 1.01版 */ ...

  10. [Angular Directive] 3. Handle Events with Angular 2 Directives

    A @Directive can also listen to events on their host element using @HostListener. This allows you to ...