【二分匹配】 hdu1083 Courses

蓝牙Channel Sounding为真正的距离感知赋能 1:工作原理蓝牙™信道探测使用两种经过验证的测距方法——PBR(PBR)和RTT(RTT),实现蓝牙设备之间的安全精密测距。 阅读详情

Courses

http://acm.hdu.edu.cn/showproblem.php?pid=1083

Problem Description
Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is possible to form a committee of exactly P students that satisfies simultaneously the conditions:

. every student in the committee represents a different course (a student can represent a course if he/she visits that course)

. each course has a representative in the committee

Your program should read sets of data from a text file. The first line of the input file contains the number of the data sets. Each data set is presented in the following format:

P N
Count1 Student1 1 Student1 2 ... Student1 Count1
Count2 Student2 1 Student2 2 ... Student2 Count2
...... 
CountP StudentP 1 StudentP 2 ... StudentP CountP

The first line in each data set contains two positive integers separated by one blank: P (1 <= P <= 100) - the number of courses and N (1 <= N <= 300) - the number of students. The next P lines describe in sequence of the courses . from course 1 to course P, each line describing a course. The description of course i is a line that starts with an integer Count i (0 <= Count i <= N) representing the number of students visiting course i. Next, after a blank, you'll find the Count i students, visiting the course, each two consecutive separated by one blank. Students are numbered with the positive integers from 1 to N.

There are no blank lines between consecutive sets of data. Input data are correct.

The result of the program is on the standard output. For each input data set the program prints on a single line "YES" if it is possible to form a committee and "NO" otherwise. There should not be any leading blanks at the start of the line.

An example of program input and output:
 

Sample Input
  
2 3 3 3 1 2 3 2 1 2 1 1 3 3 2 1 3 2 1 3 1 1
 

Sample Output
  
YES NO

题意:要从每个选了本课程的学生中挑选一个当代表,要求每个课程都要选出一个人,而且每个人只能当选一个课程的代表,问能否达成上述要求。

解法:很吃果果的二分匹配,求出最大匹配数是否等于课程数,是则可以完成。


//匈牙利算法
#include<cstdio>
#include<cstring>
using namespace std;
#define MAX 305
bool path[MAX][MAX],visit[MAX];
int match[MAX];
bool SearchPath(int s,int m)
{
    for(int i=1; i<=m; ++i)
    {
        if(path[s][i]&&!visit[i])
        {
            visit[i]=true;
            if(match[i]==-1||SearchPath(match[i],m))
            {
                match[i]=s;
                return true;
            }
        }
    }
    return false;
}
int main()
{
    int T,n,m,t,b;
    scanf("%d",&T);
    for(;T--;)
    {
        memset(path,false,sizeof(path));
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;++i)
        {
            scanf("%d",&t);
            for(;t--;)
            {
                scanf("%d",&b);
                path[i][b]=true;
            }
        }
        int summ=0;
        memset(match,-1,sizeof(match));
        for(int i=1; i<=n; ++i)
        {
            memset(visit,false,sizeof(visit));
            if(SearchPath(i,m))
                summ++;
        }
        if(summ==n)
            puts("YES");
        else
            puts("NO");
    }
    return 0;
}


来源:http://blog.youkuaiyun.com/acm_ted/article/details/7779464



5.30华为OD机试真题 新系统 - 链表数字游戏 (Java/Py/C/C++/Js/Go) 5.30华为OD机试真题 新系统 - 链表数字游戏 (Java/Py/C/C++/Js/Go) 阅读详情

相关推荐

SWAT模型参数太多搞不定?一篇讲清如何用SWAT-CUP筛选关键敏感参数(含结果图解读)

本文详细解析了如何使用SWAT-CUP进行参数敏感性分析,帮助水文模型初学者从上百个参数中筛选出关键敏感参数。通过实际案例和结果图解读,介绍了敏感性分析的核心价值、SWAT-CUP结果界面解读方法以及参数筛选的四步实战法,显著提升模型调试效率。文章还提供了典型问题排查手册,解决敏感参数与文献不一致、率定后模型变差等常见问题。

weixin_30385925的博客 320

【HDU 1083】Courses(匈牙利算法)

题意描述:有p门课程,n个学生,每门课程可能有不止一名学生选,每个学生在一个committee代表一门课程,求学生和课程的最大匹配,若最大匹配等于p,输出YES,否则输出NO。 解题思路:入门级的二分图匹配问题,对课程—学生关系建立一个图,进行二分图的最大匹配,看最大匹配数是否等于课程数即可,使用模板即可。 错误分析:要注意输入的序号。 Consider a group of N students and P courses. Each student visits zero, one o..

zz_xun的博客 240

publisher与subscriber话题的消息类型md5sum不一致问题

[ERROR] [1604235557.591296096]: Client [/range_vision_fusion_01] wants topic /detection/vision_objects to have datatype/md5sum [autoware_msgs/DetectedObjectArray/13415342e539aa36ea9a6f04ffaf39b4], but our version has [autoware_msgs/DetectedObjectArray/c16a

cxhmike的博客 6620

HDU1083——Courses和匈牙利算法的匹配过程

假设我们有两个集合(比如人员集合和任务集合),如果人员和任务之间存在可能的关联(如人员可以执行某个任务)则构建一个二维矩阵来表示这种关系,矩阵元素可以是成本(如果是求最小成本匹配)、关联强度等。从原理上,通过不断调整矩阵中0元素的分布和通过覆盖线条数来判断是否达到最大(或完整)匹配,是基于这样的逻辑:每次调整都在尝试探索新的匹配路径和组合。

u014114223的博客 914

STM32F429网络通信避坑指南:用CubeMX搞定LAN8720+LWIP+FreeRTOS(附完整代码)

本文详细介绍了STM32F429通过CubeMX配置LAN8720+LWIP+FreeRTOS实现网络通信的避坑指南,涵盖硬件连接、CubeMX配置、LWIP优化及调试技巧,提供完整代码和实战经验,帮助开发者高效解决以太网通信中的常见问题。

weixin_26873711的博客 145

别再手动连线了!用Tessent IJTAG的SIB和TDR,5分钟搞定复杂芯片的DFT网络分区

本文探讨了如何利用Tessent IJTAG的SIB(Segment Insertion Bit)和TDR(Test Data Register)技术,高效解决复杂芯片DFT网络分区问题。通过智能化的扫描链管理和声明式定义,显著降低连接复杂度,提升测试覆盖率和良率,适用于超大规模SoC设计。

weixin_29251131的博客 300

【HDU - 1083】Courses(二分图匹配)

Courses HDU - 1083 考虑一组 N 学生和 P 课程。每个学生访问零,一个或多个课程。你的任务是确定是否可能成立一个由P学生组成的委员会,同时满足条件: 。 。委员会中的每一个学生代表不同的课程(如果学生访问该课程,他可以代表一门课程)。 每个课程都有一名代表参加委员会 您的课程,应从文本文件中读取成套数据。输入文件的第一行包含数据集的数量。每个数据集以以下格式呈现: P N 计数 1 学生 1 1 学生 1 2…学生1 计数 1 计数2 学生2 1 学生2 2…学生2计数2。 伯爵P学生P

m0_58245389的博客 223

unity转微信小游戏:使用CDN加载游戏(微信开发者工具云开发CDN)

unity转微信小游戏:使用CDN加载游戏(微信开发者工具云开发CDN)

会潜水的小火龙的博客 3071

HDU 1083 二分匹配

题目大意:有n个学生,p门课程,一个学生可以选修多门课程,现在要为这p门课程分别选一个课代表,且一个学生只能当一个科目的课代表,问是否能满足所有课程都找到课代表。 运用常用模板: #include using namespace std; const int N = 310; int map[N][N], flag[N]; int pre[N]; int n, m, num; int

vsooda的专栏 1438

【学习系列】SAP RAP 4:通过注解来完成一些常规需求

本文介绍了RAP应用中常用注解的实现方式,包括搜索帮助、文本描述绑定、联动搜索、字段控制等功能。通过@Consumption、@UI等注解可以实现搜索帮助定义、多字段联动、必输校验、默认排序和默认值设置。管理字段可通过@Semantics注解自动记录创建/修改信息,长文本使用@UI.multiLineText实现多行显示。这些注解可优化界面交互和数据管理,为后续行为定义功能开发奠定基础。文章结构清晰,针对不同需求提供了具体的实现方案和代码示例。

DeveloperMrMeng的博客 696

【异常】OpenClaw总Token超限400报错400 Total tokens of image and text exceed max message tokens. Request id:

摘要: 多模态大模型调用中,图文总Token超限导致的400报错是常见问题。本文分析了该报错的触发原因(文本+图片Token总和超出接口限额),并从技术层面解释了多模态Token的计数规则。解决方案分为三个层次:1)紧急修复(精简文本、压缩图片、拆分请求);2)标准化根治(预校验Token、图片预处理、限额适配);3)进阶兜底(分块处理、模型升级、容错机制)。通过前置管控与源头优化,可有效解决并预防此类问题,提升业务稳定性。

奶爸的编程之路,也就一周冷个三天 831

hdu 1083

题目概述: 有times组数据 有P个课程,N个人 每个课程可由times(和上面的不是一个变量)个人学,可学的人编号为num 输入: 第一行times(组数据),下一行P,N,其后P行,每行一个times(个人),其后times个num 输入共有times组 限制: 1 输出: 每行一个字符串,如果每个课都有学生学,而每个学生至多学一门课,则为 YES 否则为

[CHN]liurui 407

Spring Boot Jar包加密实战:用ClassFinal与Jasypt打造代码安全堡垒

Spring Boot代码加密与配置保护方案 针对Spring Boot项目源码和配置易被反编译的风险,本文提出ClassFinal字节码加密+Jasypt配置加密的组合方案。ClassFinal通过Maven插件对核心代码加密,运行时需JavaAgent加载,反编译后仅保留空方法体;Jasypt则采用强加密算法保护敏感配置。方案优势包括: 双重保护:ClassFinal加密业务逻辑,Jasypt加密数据库密码等配置 灵活部署:支持密码启动、机器绑定等安全策略 平滑集成:兼容Spring生态,动态解密结合配

墨夶的博客 1092

HDU1083 Courses 二分匹配

HDU1083 Courses 二分匹配

NNDXNM的专栏 746

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

HDU 1083 二分匹配 Courses

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1083 分析:从第一个学生开始,先假定他任某一门课的课代表,然后再看第二个学生有没有选的,如果第二个学生他所学的课都有人预定了,那再看预定这些课的那些学生,如果他们之间有人还可以选其他的课,则让那个人选其他的,让第二个人预定那个人以前定的那门课,以些类推,最后看每门课是否都有人选.这就就答案了. #

PWZER 907

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

hdu 1083 简单的二分匹配 Courses

题目 http://acm.hdu.edu.cn/showproblem.php?pid=1083 这是一个简单的求最大匹配的问题 有二种方法   ac1 #include #include #include using namespace std; bool map[101][301]; bool mark[301]; int cx[101],cy[301]; //cx表示有多少门课

aibianchendewo的专栏 599

HDU 1083 Courses 二分匹配

题意:有n个学生,p个课程,一个学生可以选多个课程,求出是否可以组成一个集合,集合里正好有p个学生,每个学生正好对应选p个不同的课程 思路:求最大匹配,判断是否等于p即可 #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<vector&g...

qq_42397248的博客 217

杭电 hdu 1083 Courses (二分匹配 )

杭电 hdu 1083  Courses  (二分匹配 ) Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4743    Accepted Submission(s): 2278

thestarfish的博客 558

【二分匹配】HDU1083-Courses

Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3645    Accepted Submission(s): 1745 Problem Description Consider a group of N

程序猿之洞 1207

HDU-1083-Courses [二分匹配]

题目传送门题意:有P门课程和N个学生,每门课程有0-N个学生参加,问可不可以选出每门课的课代表,要求一个学生只能当一个课程的课代表。思路:裸的二分匹配,匈牙利算法。#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #incl

裤头是叫裤头的裤头 293

hdu1083Courses 二分匹配

直接模板#include &lt;iostream&gt; #include &lt;cstring&gt; #include &lt;queue&gt; #include &lt;vector&gt; #include &lt;map&gt; #include &lt;cstdio&gt; #include &lt;stdio.h&gt; #include &lt;algorithm&a

加油 (•̀ᴗ•́)و ̑̑ 189

hdu 1083 Courses (简单二分匹配)

Courses Problem Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is possible to form a committee of exactly P students that satisfies simultaneously the

Coding A World 900

HDU 1083 Courses(二分匹配匈牙利算法模板题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1083 Problem Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to de...

2728

HDU 1083 Courses 二分匹配匈牙利算法模板

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1083 Problem Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine...

qq_37136305的博客 214

hdu Courses 1083 二分匹配 ,匈牙利算法。。水题

Problem Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is possible to form a committee of exactly P students that satisfies simultaneously the condition

Lionel 1235

hdu 1083 Courses(二分匹配之匈牙利算法)

题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1083 Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5098    Accepted Submiss

ACMan 396
上一篇: 【二分匹配】 hdu2458 Kindergarten
下一篇: 【二分匹配】 poj2060 Taxi Cab Scheme
ACM_Ted
博客等级 码龄15年 122粉丝 208原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值