您当前的位置: 首页 > 

钟钟终

暂无认证

  • 2浏览

    0关注

    233博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

P3033 [USACO11NOV]Cow Steeplechase G(类似最小路径覆盖)

钟钟终 发布时间:2022-02-10 23:34:12 ,浏览量:2

https://www.luogu.com.cn/problem/P3033 P3033 [USACO11NOV]Cow Steeplechase G 哭了哭了,本来想看网课的,这个题花了我快2个小时了。。。。还好是个蓝题,不然亏大了 认真总结下: 1.首先250250数据过万,肯定要使用链式前向星的方式存图。 2.本题难点在于建立图形,把竖着的线段作为上结点,与之相交的下结点建立线段;横着的直线作为下结点,求最大匹配树,这是是最小顶点覆盖 3.n-这个值,剩下的线段就互相没有关系,就是答案。 4.剩下的就是匈牙利算法的模板啦*

#include 
#define y1 y11
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=1e6+5;
int link[maxn],n,head[maxn],cnt;
int p[maxn],x1[maxn],y1[maxn],x2[maxn],y2[maxn],n1;
bool used[maxn];
struct node
{
    int to,nxt;
}e[maxn];
void add_edge(int from,int to)
{
    e[++cnt].to=to;
    e[cnt].nxt=head[from];
    head[from]=cnt;
}
bool dfs(int u)
{
    for(int i=head[u];i;i=e[i].nxt)
    {
        int v=e[i].to;
        if(!used[v])
        {
            used[v]=1;
            if(link[v]==-1||dfs(link[v]))
            {
                link[v]=u;
                return 1;
            }
        }
    }
    return 0;
}
int hungary()
{
    memset(link,-1,sizeof(link));
    int ret=0;
    for(int i=1;iy2[i]) swap(y1[i],y2[i]);
        if(x1[i]==x2[i]) p[i]=1,n1++;  //竖着的点的个数
        else
            p[i]=2;
    }
    for(int i=1;i            
关注
打赏
1664378814
查看更多评论
0.0667s