首页 > 其他分享 >hdu2063过山车

hdu2063过山车

时间:2024-09-20 22:23:19浏览次数:1  
标签:pre map int hdu2063 vis boolean 过山车 sc

1、匈牙利算法;

2、二分图最大匹配

import java.util.Scanner;

public class Main {

    public static boolean find(int cur, int[] pre, boolean[][] map, boolean[] vis){
        for (int i = 1; i < pre.length; i++) {
            if (map[cur][i] && !vis[i]){
                vis[i] = true;
                if (pre[i]==-1 || find(pre[i],pre,map,vis)){
                    pre[i] = cur;
                    return true;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            int hang = sc.nextInt();
            if (hang==0){
                break;
            }
            int res = 0;
            int girl = sc.nextInt();
            int boy = sc.nextInt();
            /*女找男*/
            int[] pre = new int[boy+1];/*记录男的被谁选择了*/
            boolean[][] map = new boolean[girl+1][boy+1];
            boolean[] vis = new boolean[boy+1];/*临时记录男的是否 被选*/
            for (int i = 1; i <= boy; i++) {
                pre[i] = -1;
            }
            for (int i = 0; i < hang; i++) {
                int aa = sc.nextInt();
                int bb = sc.nextInt();
                map[aa][bb] = true;
            }
            for (int i = 1; i <=girl ; i++) {
                for (int j = 1; j <=boy ; j++) {
                    vis[j] = false;
                }
                if (find(i,pre,map,vis)){
                    res++;
                }
            }
            System.out.println(res);
        }

    }
}

 

标签:pre,map,int,hdu2063,vis,boolean,过山车,sc
From: https://www.cnblogs.com/xiaohuangTX/p/18423405

相关文章

  • 股价经历了过山车般波动后,高途仍面临重大政策风险
    最近几个月影响高途股价的主要事件在过去的两个半月里,高途(GOTU)的股价就像坐过山车一样,根据S&PCapitalIQ的数据,高途的股价在2023年2月8日的交易日结束时,从1.00美元迅速暴涨到了3.30美元,涨幅达到了230%。在2022年12月22日,高途的股价也从2022年11月25日交易日开始的1.00美元迅速暴涨......