zoukankan      html  css  js  c++  java
  • BZOJ1191: [HNOI2006]超级英雄Hero

    【传送门:BZOJ1191


    简要题意:

    给出m个问题,给出n个锦囊,每个问题可以用两种锦囊解决(有可能这两种锦囊是同一种,这就很尴尬,可能出数据的神犇有点儿懒),但每种锦囊只能用一次,而且只有解决了前面的问题才能解决后面的问题,求出最多能解决多少问题


    题解:

    就是很裸的二分图匹配啦,直接匈牙利。


    参考代码:

    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    struct node
    {
        int x,y,next;
    }a[2100];int len,last[2100];
    int match[2100];
    void ins(int x,int y)
    {
        len++;
        a[len].x=x;a[len].y=y;
        a[len].next=last[x];last[x]=len;
    }
    bool chw[2100];
    bool findmuniu(int x)
    {
        for(int k=last[x];k;k=a[k].next)
        {
            int y=a[k].y;
            if(chw[y]==true)
            {
                chw[y]=false;
                if(match[y]==0||findmuniu(match[y])==true)
                {
                    match[y]=x;
                    return true;
                }
            }
        }
        return false;
    }
    int main()
    {
        int n,m;
        scanf("%d%d",&n,&m);
        memset(match,0,sizeof(match));
        len=0;memset(last,0,sizeof(last));
        for(int i=1;i<=m;i++)
        {
            int y1,y2;
            scanf("%d%d",&y1,&y2);
            y1++;y2++;
            if(y1==y2) ins(i,y1+m);
            else
            {
                ins(i,y1+m);
                ins(i,y2+m);
            }
        }
        int ans=0;
        for(int i=1;i<=m;i++)
        {
            memset(chw,true,sizeof(chw));
            if(findmuniu(i)==true) ans++;
            else break;
        }
        printf("%d
    ",ans);
        return 0;
    }
    渺渺时空,茫茫人海,与君相遇,幸甚幸甚
  • 相关阅读:
    要离职了。
    上海找工作经历
    1.6. 三基色LED
    1.5. 板载LED PWM模式
    1.4. 板载LED控制
    1.3. 硬件篇之IO口(视频连接)
    1.2 Hello World
    1.8. 数码管
    ESP32编译自己的micropython固件
    1.1 准备工作
  • 原文地址:https://www.cnblogs.com/Never-mind/p/7526044.html
Copyright © 2011-2022 走看看