Courses(hdu 1083)

卫星监测“America”级#两#栖#攻#击#舰#(LHA-6)出港 卫星监测“America”级#两#栖#攻#击#舰#(LHA-6)出港 前脚刚走,后脚又来,山姆大叔又来刷存在感,2020年7月28日,USS Ronald Reagan流窜在我国东海海区被卫星拍了下来: 2020年8月1日,最新卫星图像显示USS Ronald Reagan已经返回母港日本横须贺:距离其出港(2020年6月8日)已经过去了快两个月 然而事情并没有到此结束,“America”级#两#栖#攻#击#舰#(LHA-6)选择在 “八.一” 这个特殊的日子前后出港颇具挑衅的味道。 根据2020年 阅读详情

题目描述:

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.

样例输入:

2
3 3
3 1 2 3
2 1 2
1 1
3 3
2 1 3
2 1 3
1 1

样例输出:

YES
NO 

code:

很明显,这是一个入门级的二分图匹配问题

需要使用模板即可

不过要注意输入的序号

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn=650;
int n,m;
vector<int> g[maxn];
int match[maxn];
bool used[maxn];
void init(){
	int number=n+m;
	for(int i=0;i<=number;i++){
		g[i].clear();
	}
}
void add_edge(int u,int v){
	g[u].push_back(v);
	g[v].push_back(u);
}
bool dfs(int v){
	used[v]=true;
	for(int i=0;i<g[v].size();i++){
		int u=g[v][i],w=match[u];
		if(w<0||!used[w]&&dfs(w)){
			match[v]=u;
			match[u]=v;
			return true;
		}
	}
	return false;
}
int findd(){
	int res=0;
	memset(match,-1,sizeof(match));
//	init();
	int number=n+m;
	for(int v=1;v<=number;v++){
		if(match[v]<0){
			memset(used,0,sizeof(used));
			if(dfs(v))res++;
		}
	}
	return res;
}
int main()
{
	int ttt;
	scanf("%d",&ttt);
	while(ttt--){
		scanf("%d%d",&n,&m);
		int t;
		init();
		for(int i=1;i<=n;i++){
			scanf("%d",&t);
			while(t--){
				int jiang;
				scanf("%d",&jiang);
				add_edge(jiang+n,i);
			}
		}
		int what=findd();
		if(what>=n)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
} 

或者,匈牙利算法走一波

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<vector>
using namespace std;
int n,m;
const int maxn=350;
int pre[maxn];
vector<int> match[maxn];
int visit[maxn];
void init(){
	for(int i=0;i<maxn;i++){
		match[i].clear();
	}
	memset(pre,0,sizeof(pre));
}
bool dfs(int x){
	for(int i=0;i<match[x].size();i++){
		int j=match[x][i];
		if(visit[j]==0){
			visit[j]=1;
			if(pre[j]==0||dfs(pre[j])){
				pre[j]=x;
				return true;
			}
		}
	}
	return false;
}
int findd(){
	int sum=0;
	for(int i=1;i<=n;i++){
		memset(visit,0,sizeof(visit));
		if(dfs(i))sum++;
	}
	return sum;
}
int main()
{
	int ttt;
	scanf("%d",&ttt);
	while(ttt--){
		init();
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++){
			int t,y;
			scanf("%d",&t);
			while(t--){
				scanf("%d",&y);
				match[i].push_back(y);
			}
		}
		int num=findd();
		if(num==n)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

 

Python电商网站全站爬虫实战:以京东为例的数据采集与分析 随着电子商务的蓬勃发展,电商数据已成为市场研究、竞争分析和消费者行为研究的重要资源。本文详细介绍了如何使用Python最新技术栈构建一个高效的电商网站全站爬虫,以京东为例实现商品数据的自动化采集。文章涵盖了爬虫的法律与伦理考量、技术选型、反爬虫策略应对、分布式架构设计以及数据存储方案,并提供了完整的代码实现。本爬虫系统采用Scrapy-Redis分布式框架、Selenium动态渲染、智能代理轮换和机器学习验证码识别等先进技术,能够稳定高效地抓取京东全站商品数据,为电子商务研究提供数据支持。关键词。 阅读详情

相关推荐

关于LIO-SAM编译时出现错误 /usr/bin/ld: 找不到 -lBoost::timer

关于LIO-SAM编译时出现错误: 下载LIO-SAM代码 进入LIO-SAM文件夹,通过以下代码编译: mkdir build cd build cmake .. make 报错: /usr/bin/ld: 找不到 -lBoost::timer collect2: error: ld returned 1 exit status CMakeFiles/lio_sam_imuPreintegration.dir/build.make:759: recipe for target 'devel/lib/li

wwtx的博客 3648

HDOJ1083(Courses)

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

weixin_30252709的博客 292

ad新版本学习笔记(基本包含一套流程)Altium Designer(ad20/ad21/ad22/ad23)

ad20-ad23学习笔记,逐渐补全

安和的博客 4万+

HDU1803 Courses(二分图匹配,匈牙利算法,dfs)

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

riba2534的博客 592

Power BI财销一体分析——KPI分析应用实践

第九步:插入三个散点图,行拖入分销商表分销商字段,将度量值中的销量拖入X轴,将利润拖入Y轴,大小拖入度量值总销售额,将分销商表业务类型字段作为筛选条件添加给散点图,分别选择专业自行车店、增值经销商、仓库,使视觉对象固定显示不同业务类型的散点分布。这个公式其实是不需要我们自己写的,依赖于快度量值功能星级评分,基值选择度量值总销售额,星数选择5,最低星值评分选择0,最高星级评分值选择100,点击添加,星级评分度量值就建立好了,接下来我们理解一下公式。好的,今天的讲解就到这里。

BI瓶子的博客 1552

PID控制算法实践应用(一):PID算法的离散化

由于计算机控制是一种采样控制,它只能根据采样时刻的偏差值计算控制量。因此,连续PID控制算法不能直接使用,需要采用离散化方法。

m0_72676510的博客 2602

COURSES - 北电1469 (二分匹配)

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 ...

ailin7729的博客 249

【PINN物理信息网络】基于PINN物理信息网络求解圆柱坐标中的热方程(python)

【PINN物理信息网络】基于PINN物理信息网络求解圆柱坐标中的热方程(python)

k8291121的博客 2273

二分图最大匹配加邻接表 - Courses - HDU - 1083

用邻接表来加快二分图的匹配速度

奥里给 272

【即插即用模块】卷积篇 | CVPR 2025 | LSConv:大核捕全局,小核提速度,替换 3×3 卷积/自注意力,精度效率双飙升

文章摘要: LSConv是一种新型卷积模块,采用"大核感知+小核聚合"策略,在轻量级视觉任务中表现出色。该模块由两部分组成:7×7深度可分离卷积(LKP)捕捉全局信息,动态3×3卷积(SKA)实现高效特征聚合。相比传统卷积和自注意力机制,LSConv在降低计算量的同时提升了精度,尤其适合高分辨率视觉任务。实验表明,在轻量化模型中用LSConv替代3×3卷积或自注意力,可显著减少计算量并提高准确率。模块支持即插即用,提供Triton优化实现,可直接集成到现有卷积或Transformer架构

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 1119

[Python从零到壹] 十四.机器学习之分类算法五万字总结全网首发(决策树、KNN、SVM、分类对比实验)

分类(Classification)属于有监督学习(Supervised Learning)中的一类,它是数据挖掘、机器学习和数据科学中一个重要的研究领域。分类模型类似于人类学习的方式,通过对历史数据或训练集的学习得到一个目标函数,再用该目标函数预测新数据集的未知属性。本章主要讲述分类算法基础概念,并结合决策树、KNN、SVM分类算法案例分析各类数据集,从而让读者学会使用Python分类算法分析自己的数据集,研究自己领域的知识,从而创造价值。 19.1 分类 19.1.1 分类模型 与前面讲述的聚类模型类似

杨秀璋的专栏 2万+

AcWing 861. 二分图的最大匹配(Java)_匈牙利算法

二分图的最大匹配①. 题目②. 思路③. 学习点④. 代码实现 原题链接 ①. 题目 ②. 思路 ③. 学习点 ④. 代码实现

780

手把手教你学SOME/IP「1.0•概述」

本文介绍了SOME/IP协议的基本概念和主要特点。SOME/IP全称为"Scalable service-Oriented MiddlewarE over IP",是一种面向服务的车载嵌入式通信协议,支持远程过程调用、事件通知等功能。文章指出SOME/IP是AUTOSAR标准的一部分,在车载以太网架构中处于应用层位置,负责服务调度和通信封装。协议具有可扩展性强、资源消耗低、兼容性好等优势,能满足汽车电子领域对实时性、可靠性的严格要求。同时,文章也说明了SOME/IP的正确书写规范,并解释

nihaoljq2010的博客 679

HDU - 1083 : Courses(匈牙利算法,二分图最大匹配)

题目链接:HDU - 1083 : Courses 题目大意:有P门课程,N个学生,每门课程有若干个学生选,且每门课都要有一个课代表,但是每个学生至多只能担任一门课的课代表,问能否每门课都能找到课代表 解题分析:将课程和学生看成二分图的左右两部分,由是否选课确定中间的连边,接下来就是裸套匈牙利算法模板了,如果最大匹配数=课程数,则输出”YES”,否则输出”NO”

Jerry的博客 502

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

hdu-1083 Courses (二分图)

原题链接 hdu-1083 Courses 题意 一共有N个学生跟P门课程,一个学生可以任意选一 门或多门课,问是否达成: 1.每个学生选的都是不同的课(即不能有两个学生选同一门课) 2.每门课都有一个代表(即P门课都被成功选过) 输入为: P N(课程数跟学生数) 接着有P行,格式为Count studenti studenti+1 ……studentcount (Count表示对课程1感兴趣...

Herobrine的博客 483

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

hdu - 1083 - Courses

hdu - 1083 - Courses 分类: 网络流2013-09-21 10:29 87人阅读 评论(0) 收藏 举报 题意:有P门课程,N个学生,每门课程有一些学生选读,每个学生选读一些课程,问能否选出P个学生组成一个委员会,使得每个学生代言一门课程(他必需选读其代言的课程),每门课程都被一个学生代言(1 题目链接:http://acm.hdu.edu.cn/sho

pi9nc的专栏 650

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

HDU-1083 Courses(匈牙利算法)

HDU-1083 Courses题目描述: 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 exac

Static_Ricardo的博客 423

HDU 1083:Courses

二分图匹配模板题

温姑娘的博客 285

hdu 1083 Courses

hdu  1083  Courses                  题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1083 图论 匈牙利算法 题目大意:有一些课程,一些学生,给出每门课程有哪些学生去上,求是否(每门课都有学生当课代表&&每个学生都当了不同科的课代表)。 题目分析:二分匹配匈牙利 #include #include usin

slicer的技术交流栈 844

HDU 1083 Courses 二分图

HDU 1083 题意 给你 p个课程 n个学生 问你每个课程是否能选出一个课代表 裸的匈牙利 直接跑 /* if you can't see the repay Why not just work step by step rubbish is relaxed to ljq */ #include <cstdio> #include <...

我是谁 --- 卡比兽 180

HDU 1083 — Courses

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1083 题意: 有p个课程n个学生; 学生可以自由选择课程,但一个学生只能代表一个课程; 接下来p行,第i行表示第i门课,第一个数m为选该门课的人数,然后列出这m个人; 问是否每门课都有学生代表; 思路: 就是求最大匹配,若匹配数为p,则YES,否则NO; #incl

吧唧吧唧 592

HDU - 1083 Courses

一、内容 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 t...

Tizzi的博客 667

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): 10314    Accepted Submission(s)...

lee371042的博客 235

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

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

u014114223的博客 914

【二分匹配】 hdu1083 Courses

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 t

Ted's 游乐园 1000

HDOJ HDU 1083 Courses

HDOJ 1083 Courses题目 图论 二分图的最大匹配 匈牙利算法

Gy_1096440940的博客 404
上一篇: 1708: 01串也疯狂之光棍也有伴
下一篇: Antenna Placement
大橘为重eleven
博客等级 码龄8年 35粉丝 103原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值