http://poj.org/problem?id=3041

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN=;
int n,k;
bool use[MAXN];
int from[MAXN],ans;
vector<int>g[MAXN];
bool match(int x)
{
for(int i=;i<g[x].size();i++)
{
if(!use[g[x][i]]){
use[g[x][i]]=true;
if(from[g[x][i]]==-||match(from[g[x][i]])){
from[g[x][i]]=x;
return true;
}
}
}
return false;
} int hun()
{ ans=;
memset(from,,sizeof(from));
for(int i=; i<=n; i++)
{
memset(use,false,sizeof(use));
if(match(i))
ans++;
}
return ans;
}
int main()
{
int a,b;
while(scanf("%d%d",&n,&k)!=EOF){
for(int i=;i<=k;i++)
{
scanf("%d%d",&a,&b);
g[a].push_back(b);
}
printf("%d\n",hun());
}
return ;
}
 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN=;
int n,k;
bool use[MAXN];
int match[MAXN],ans;
int g[MAXN][MAXN];
bool dfs(int x)
{
for(int i=;i<=n;i++)
{
if(!use[i]&&g[x][i]){
use[i]=true;
if(match[i]==-||dfs(match[i])){
match[i]=x;
return true;
}
}
}
return false;
} int hun()
{ ans=;
memset(match,-,sizeof(match));
for(int i=; i<=n; i++)
{
memset(use,false,sizeof(use));
if(dfs(i))
ans++;
}
return ans;
}
int main()
{
int a,b;
while(scanf("%d%d",&n,&k)!=EOF)
{
memset(g,,sizeof(g));
for(int i=; i<=k; i++)
{
scanf("%d%d",&a,&b);
g[a][b]=;
}
printf("%d\n",hun());
}
return ;
}

Asteroids的更多相关文章

  1. POJ 3041 Asteroids

     最小点覆盖数==最大匹配数 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12678 Accepted:  ...

  2. Asteroids(匈牙利算法入门)

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16211   Accepted: 8819 Descri ...

  3. hdu 1240:Asteroids!(三维BFS搜索)

    Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  4. POJ 3041 Asteroids(最小点覆盖集)

                                                                      Asteroids Time Limit: 1000MS   Mem ...

  5. Asteroids (最小覆盖)

    题目很简单,但是需要推到出二分图最大匹配 = 最小覆盖 最小覆盖:证明过程http://blog.sina.com.cn/s/blog_51cea4040100h152.html Descriptio ...

  6. poj 3041 Asteroids(最小点覆盖)

    http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  7. poj 3041 Asteroids (最大匹配最小顶点覆盖——匈牙利模板题)

    http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  8. HDU-1240 Asteroids! (BFS)这里是一个三维空间,用一个6*3二维数组储存6个不同方向

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission ...

  9. POJ 3041 Asteroids 最小点覆盖 == 二分图的最大匹配

    Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape o ...

  10. Asteroids(二分图最大匹配模板题)

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12323   Accepted: 6716 Description Bess ...

随机推荐

  1. Android的TextView与Html相结合的用法

    Android中的TextView,本身就支持部分的Html格式标签.这其中包括常用的字体大小颜色设置,文本链接等.使用起来也比较方便,只需要使用Html类转换一下即可.比如: textView.se ...

  2. java中的String.format使用

         format(String  format, Objece...  argues)函数相当于C语言中的printf函数,但是相对来说更灵活.      和C中的printf函数差不多,在fo ...

  3. c++逆向 vector

    最近弄Android c/c++方面的逆向,发现c++的类,stl模板,在逆向的时候相比c语言都带来了不小的困难. 今天自己写了个小程序,然后逆向分析了一下 vector<int> arr ...

  4. [转] 设计模式 -- Facade

    PS:Façade模式注重简化接口,Adapter模式注重转换接口,Bridge模式注重分离接口(抽象)与其实现,Decorator模式注重稳定接口的前提下为对象扩展功能. Facade模式 Faca ...

  5. 微信,QQ这类IM app怎么做——谈谈Websocket

    前言 关于我和WebSocket的缘:我从大二在计算机网络课上听老师讲过之后,第一次使用就到了毕业之后的第一份工作.直到最近换了工作,到了一家是含有IM社交聊天功能的app的时候,我觉得我现在可以谈谈 ...

  6. CentOS7搭建SAMBA服务器实现与WIN10匿名共享文件

    1.安装SAMBA yum -y install samba samba-client samba-common 2.修改文件打开数 vi /etc/security/limits.conf 最后添加 ...

  7. 176. [USACO Feb07] 奶牛聚会

    #include<iostream> #include<cstdio> #include<cstring> #include<queue> #defin ...

  8. msp

    10月8号加入了微软的msp项目,其实那时候对msp没有什么概念,不知道要干嘛,真的觉得大不了就退出呗,反正也没啥大事,   现在再也不那么看了,这二十多天虽然没怎么水群,但是还是一直在关注着我们这个 ...

  9. css font的简写规则

    font的属性简写里面常用的有5个是可以写在一起的: font-style设定斜体 如:font-style: italic;font-weight设定文字粗细 如:font-weight: bold ...

  10. 【转载】ASP.NET线程安全与静态变量的生命周期浅谈

    ASP.NET线程安全所涉及的是什么呢?让我们先来看看静态变量的生命周期问题,下面是我理解的静态变量的生命周期: void Application_Start开始 void Application_E ...