POJ 1422 Air Raid (二分图最小路径覆盖)

HUSTOJ 基础题组3 问题 F: Air Raid 【代码】HUSTOJ 基础题组3 问题 F: Air Raid。 阅读详情

Consider a town where all the streets are one-way and each street leads from one intersection to another. It is also known that starting from an intersection and walking through town’s streets you can never reach the same intersection i.e. the town’s streets form no cycles.

With these assumptions your task is to write a program that finds the minimum number of paratroopers that can descend on the town and visit all the intersections of this town in such a way that more than one paratrooper visits no intersection. Each paratrooper lands at an intersection and can visit other intersections following the town streets. There are no restrictions about the starting intersection for each paratrooper.
Input
Your program should read sets of data. The first line of the input file contains the number of the data sets. Each data set specifies the structure of a town and has the format:

no_of_intersections
no_of_streets
S1 E1
S2 E2
…
Sno_of_streets Eno_of_streets

The first line of each data set contains a positive integer no_of_intersections (greater than 0 and less or equal to 120), which is the number of intersections in the town. The second line contains a positive integer no_of_streets, which is the number of streets in the town. The next no_of_streets lines, one for each street in the town, are randomly ordered and represent the town’s streets. The line corresponding to street k (k <= no_of_streets) consists of two positive integers, separated by one blank: Sk (1 <= Sk <= no_of_intersections) - the number of the intersection that is the start of the street, and Ek (1 <= Ek <= no_of_intersections) - the number of the intersection that is the end of the street. Intersections are represented by integers from 1 to no_of_intersections.

There are no blank lines between consecutive sets of data. Input data are correct.
Output
The result of the program is on standard output. For each input data set the program prints on a single line, starting from the beginning of the line, one integer: the minimum number of paratroopers required to visit all the intersections in the town.
Sample Input
2
4
3
3 4
1 3
2 3
3
3
1 3
1 2
2 3
Sample Output
2
1
**题意:t组数据,对于每组数据,n代表城镇的数目,m代表单向道路数;接下来m行:u v 表示u到v有一条单向路。
现在派伞兵去遍历所有城镇,每个伞兵可以走遍它能走到的任何地方,求最小需要派多少伞兵。
题解:这是个最小路径覆盖问题,在DAG图中寻找尽量少的路径,使得每个节点恰好在一条路径上(不同的路径不可能有公共点)。我们可以发现每匹配一条路径派的伞兵就可以少一个,所以答案等于n-边最大匹配数
**

#include<stdio.h>
#include<string.h>
int n,m,ans;
int g[350][350];
int pipei[350];
int used[350];
int dfs(int x)
{
	for(int i=1;i<=n;i++)
	{
		int y=g[x][i];
		if(y&&!used[i])
		{
			used[i]=1;
			if(pipei[i]==-1||dfs(pipei[i]))
			{
				pipei[i]=x;
				return 1;
			}
		}
	}
	return 0;
}
int solve()
{
	for(int i=1;i<=n;i++)
	{
		memset(used,0,sizeof(used));
		ans+=dfs(i);
	}
}
int main()
{
	int t,u,v;
	scanf("%d",&t);
	while(t--)
	{
		ans=0;
		memset(pipei,-1,sizeof(pipei));
		memset(g,0,sizeof(g));
		scanf("%d %d",&n,&m);
		for(int i=0;i<m;i++)
		{
			scanf("%d %d",&u,&v);
			g[u][v]=1;
		}
		solve();
		printf("%d\n",n-ans);
	}
	
	return 0;
} 
ubuntu安装glibc VSCode 在ubuntu下调试无法打开libc-start.c raise.c等1. 安装glibc2. launch.json中添加路径映射3. 调试 1. 安装glibc apt install glibc-source cd /usr/src/glibc/ sudo tar -xvf glibc-[VERSION].tar.xz 2. launch.json中添加路径映射 "sourceFileMap": { "/build/glibc-S7xCS9": "/usr/src/glib 阅读详情

相关推荐

【已解决】如何在服务器中下载huggingface模型,解决huggingface无法连接

在服务器上使用huggingface模型时,如果直接指定模型名称,用AutoTokenizer.from_pretrained(“model_name”),可能会由于网络原因会报错 Failed to connect to huggingface.co port 443 after 75018 ms: Operation time out因此我们需要下载模型到服务器上,得到模型本地的路径model_dir,再通过AutoTokenizer.from_pretrained(model_dir)方式来使用。

a61022706的博客 4万+

POJ1422 Air Raid【二分图最小路径覆盖】

题目大意: 有N个地点和M条有向街道,现在要在点上放一些伞兵,伞兵可以沿着有向街道走,直到不能走为止。 每条边只能被一个伞兵走一次。问:至少放多少伞兵,能使伞兵可以走到图上所有的点。 思路: 很明显的最小路径覆盖问题。先转换为二分图,先将N个点每个点拆成两个点,左边是1~N个点,右 边也是1~N个点。将有向街道变为左边点指向右边点的边。 因为二分图最小路径覆盖 = 点数 - 二分图最大匹配数,则求出结果就是放的最少伞兵数。

程序员充电站(itcharge) 1020

深入Linux网络子系统:STMMAC驱动如何通过MDIO总线与PHY芯片“对话”

本文深入解析了Linux网络子系统中STMMAC驱动通过MDIO总线与PHY芯片的通信机制。详细介绍了MDIO总线的注册流程、PHY设备的绑定机制以及设备树配置,帮助开发者理解MAC控制器与PHY芯片的协作基础,优化网络通信性能。

weixin_26897585的博客 448

【二分图|最小路径覆盖】POJ-1422 Air Raid

Air Raid Time Limit: 1000MS   Memory Limit: 10000K       Description Consider a town where all the streets are one-way and each street leads from one intersection to anot

JSure的代码库 1101

RTPS规范v2.3(中文版)

DDSI-RTPSv2.3,DDS发现互操作性-实时发布订阅通信协议,中文版

pony12的专栏 752

磁栅尺的基本原理

一、磁栅尺简介 磁栅尺(Magnetic scale)是一种常见于工业自动化设备领域的线性位移测量方案,因为其耐用性强,对环境要求不高,逐渐替代了对环境要求苛刻的光学直线测量方案。 作为自动化设备领域里不多见的精密位移检测方案,磁栅尺使用广泛,尤其适用于检测行程长、测量精度要求高、工况复杂的大型机床。磁栅尺安装方便,抗干扰能力强,抗冲击性强,不易受到振动、粉尘、水垢、油污等影响,耐高温和耐低温性能也较为突出。 二、磁栅尺基本组成与原理 磁栅尺主要由两个部分组成,磁尺和读磁头。 磁尺 磁尺是磁栅尺

Luckboy_shy的博客 1万+

POJ 1422 Air Raid(二分图匹配+最小路径覆盖+匈牙利算法)

Consider a town where all the streets are one-way and each street leads from one intersection to another. It is also known that starting from an intersection and walking through town's streets you can never reach the same intersection i.e. the town's stree

HJY 400

【毕设保姆级指南】基于YOLOv8的DAGM 2007工业缺陷检测系统从搭建到落地

本教程基于YOLOv8算法实现DAGM 2007工业缺陷检测系统,包含数据处理、模型训练和可视化界面开发全流程。首先对DAGM数据集进行格式转换和划分,然后通过YOLOv8训练工业缺陷检测模型,最终构建PyQt5交互界面实现缺陷可视化检测。该系统可用于智能制造中的产品质量控制,帮助快速定位工业产品缺陷,提升检测效率和准确性,为工业质检提供高效解决方案。

LXY_LOVE36的博客 182

poj 1422 Air Raid 最小路径覆盖 二分图匹配 解题报告

Description Consider a town where all the streets are one-way and each street leads from one intersection to another. It is also known that starting from an intersection and walking through town's

小夥的博客 1263

27、物联网中的量子密钥分发:安全通信新范式

本文探讨了物联网(IoT)快速发展所带来的安全挑战,并提出量子密钥分发(QKD)作为应对新兴威胁的新范式。文章详细介绍了QKD的基础原理、BB84协议的实现流程以及其在物联网中的应用前景,同时强调了安全专业人员提升技能、制定标准化指南以及跨学科合作的重要性。通过利用量子力学特性,QKD能够提供更高的通信安全性,抵御量子计算等未来威胁,为物联网的安全发展提供保障。

tequila的博客 156

基于Simulink的PID控制器自动驾驶仿真建模示例

本文通过Simulink仿真平台,详细讲解了基于PID控制器的自动驾驶路径跟踪实现方法。主要内容包括:1)建立自行车运动学模型作为被控对象;2)定义参考路径与横向误差计算方法;3)设计PD控制器并调试参数;4)在Simulink中搭建完整仿真模型;5)分析30km/h车速下的双移线跟踪性能。文章强调PID控制作为自动驾驶入门基础的重要性,并指出其在中低速场景下的适用性,同时给出了工程实践中的优化建议(如前视距离、抗积分饱和等)和扩展方向(如Stanley控制器)。通过完整案例,帮助读者掌握车辆运动学建模和P

xiaoheshang_123的博客 65

POJ1422-Air Raid-二分图-DAG最小路径覆盖

题目地址 http://poj.org/problem?id=1422 二分图基础知识:http://www.cnblogs.com/HITLJR/p/5782110.html 模板题没有思维含量,但是二分图和DAG最小路径覆盖的关系,需要仔细想明白。 代码 1 #include <iostream> 2 #include <cstring>...

bandi8620的博客 181

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

POJ 1422 Air Raid(二分图匹配最小路径覆盖)

POJ 1422 Air Raid 题目链接 题意:给定一个有向图,在这个图上的某些点上放伞兵,可以使伞兵可以走到图上所有的点。且每个点只被一个伞兵走一次。问至少放多少伞兵 思路:二分图的最小路径覆盖,每个点拆成两个点,然后根据有向边连边,然后答案为n - 最大匹配数 代码: #include #include #include #include using

Remilia's 1017

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

POJ 1422 && ZOJ 1525 --Air Raid【二分图 && 最小路径覆盖】

Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7451   Accepted: 4434 Description Consider a town where all the streets are one-way and each stree

_阿阿阿阿欢 786

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

poj 1422 Air Raid(最小路径覆盖 + 二分图最大匹配)

http://poj.org/problem?id=1422 题意:在一个有向无环图中,从一些顶点出发,能遍历到图上所有点,要求初始选择的顶点数最少且顶点不重复遍历。 思路: 如果从某个顶点开始遍历的过程看成是路径的选择,那么问题就转化为在有向无环图中找最少的不想交的简单路径,这些路径覆盖图中的所有顶点。可见是关于最小路径覆盖的问题。 在有向无环图中,最小路径覆盖数  =

2129

POJ 1422 Air Raid (二分图+有向图最小不相交路径覆盖)

Consider a town where all the streets are one-way and each street leads from one intersection to another. It is also known that starting from an intersection and walking through town's streets you ...

vocaloid01的博客 406

POJ 1422Air Raid(二分图最大匹配之最小路径覆盖)

题目地址:http://poj.org/problem?id=1422 这题纯裸d

scf0920 928

POJ 1422 Air Raid 最小路径覆盖(二分图匹配)

一个PXP的有向图中,路径覆盖就是在图中找一些路径,使之覆盖了图中的所有顶点,且任何一个顶点有且只有一条路径与之关联;(如果把这些路径中的每条路径从它的起始点走到它的终点,那么恰好可以经过图中的每个顶点一次且仅一次);如果不考虑图中存在回路,那么每条路径就是一个弱连通子集.   由上面可以得出:   1.一个单独的顶点是一条路径;   2.如果存在一路径p1,p2,.

水 1007

POJ 1422 Air Raid - 最小路径覆盖(二分图)-易错题

考察内容:最小路径覆盖 题意:给定一张有向图,每个节点只能经过一次,求最小路径覆盖数 易错点: 注意Floyd传递闭包与否取决于一个节点能否经过多次 考虑二分图求最小路径覆盖即为匹配出一个点的前驱和后驱, 而对于节点只能经过一次的情况,不能存在路径交叉 eg:a1->b->c1,a2->b->c2,若传递闭包判断连通性,则匹配为     a2-c2,a1-b-c1,其

x_1023的博客 253

POJ-1422-Air Raid(二分图最小路径覆盖)

裸的最小路径覆盖 最小路径覆盖=顶点数-二分图最大匹配 // File Name: 1422.cpp // Author: zlbing // Created Time: 2013/2/27 19:20:35 #include<iostream> #include<string> #include<algorithm> #include&...

weixin_30648587的博客 98

POJ-1422-Air Raid (二分图 最小路径覆盖)

Air Raid Description Consider a town where all the streets are one-way and each street leads from one intersection to another. It is also known that starting from an intersection and walking thr

bobo 556

POJ1422——Air Raid(二分图,最小路径覆盖)

Description Consider a town where all the streets are one-way and each street leads from one intersection to another. It is also known that starting from an intersection and walking through town's

Beyond the Sora 452

poj1422-最小路径覆盖(不交叉)&二分图-Air Raid

https://vjudge.net/problem/POJ-1422 给定一个图。点代表小城镇,边代表小城镇的路,你可以再一个点投一个伞兵,那个sb可以出发,经过任何他所经过的点,问你最少投多少伞兵。 要求①:伞兵不可以交叉。 思路① dfs?但是是有向图,不是求连通分量那种。 ② topsort也是不行的,因为只能求topsort并不能确定有分叉的情况。 ③ 正

天与云与山与水 334
上一篇: HDU 2072 单词数map/set - 优快云博客
下一篇: 蓝桥杯b组 包子凑数
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值