zoukankan      html  css  js  c++  java
  • POJ 2536 Gopher II(二分图最大匹配)

    题意:

    N只地鼠M个洞,每只地鼠、每个洞都有一个坐标。

    每只地鼠速度一样,对于每只地鼠而言,如果它跑到某一个洞的所花的时间小于等于S,它才不会被老鹰吃掉。

    规定每个洞最多只能藏一只地鼠。

    问最少有多少只地鼠会命丧鹰口。

    思路:

    直接建图。二分图最大匹配。

    代码:

    char st[105];
    char Range[25][5];
    int n;
    int num[10];
    int cx[25],cy[205];
    bool bmask[205];
    vector<int> graph[25];
    
    
    int findPath(int u){
        int L=graph[u].size();
        rep(i,0,L-1){
            int v=graph[u][i];
            if(!bmask[v]){
                bmask[v]=true;
                if(cy[v]==-1||findPath(cy[v])){
                    cy[v]=u;
                    cx[u]=v;
                    return 1;
                }
            }
        }
        return 0;
    }
    int MaxMatch(){
        int ans=0;
        rep(i,1,n) cx[i]=-1;
        rep(i,1,num[5]) cy[i]=-1;
        rep(i,1,n) if(cx[i]==-1){
            mem(bmask,false);
            ans+=findPath(i);
        }
        return ans;
    }
    
    int main(){
        map<char,int> mp;
        mp['S']=1; mp['M']=2; mp['L']=3; mp['X']=4; mp['T']=5;
        while(scanf("%s",st)!=EOF){
            if(strcmp(st,"ENDOFINPUT")==0) break;
            scanf("%d",&n);
            rep(i,1,n) scanf("%s",Range[i]);
    
            num[0]=0;
            rep(i,1,5){
                int x;
                scanf("%d",&x);
                num[i]=num[i-1]+x;
            }
            scanf("%s",st);
    
            rep(i,1,n) graph[i].clear();
            rep(i,1,n){
                int u=mp[Range[i][0]], v=mp[Range[i][1]];
                rep(j,num[u-1]+1,num[v]) graph[i].push_back(j);
            }
            int dd=MaxMatch();
            if(dd>=n)
                puts("T-shirts rock!");
            else
                puts("I'd rather not wear a shirt anyway...");
        }
    }
  • 相关阅读:
    python绘图02
    python验证码
    Python绘图
    idea maven web项目tomcat本地部署
    Spark入门之环境搭建
    假期计划
    This program may be freely redistributed under the terms of the GNU GPL
    大学生恋爱观调查报告
    Python数据分析TMDb 5000 Movie Database电影数据分析
    动态添加HTML时onclick函数参数传递
  • 原文地址:https://www.cnblogs.com/fish7/p/4094931.html
Copyright © 2011-2022 走看看