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;
} 
双模音频解码器设计:USB+蓝牙LDAC平衡输出方案 音频解码器是数字音频系统中实现数模转换的核心组件,其性能直接决定音质保真度与系统延迟。基于高集成SoC的解码方案通过统一时钟域与片内DSP处理,有效抑制Jitter并简化硬件拓扑;结合全平衡模拟输出架构,可显著提升共模抑制比(CMRR)与信噪比(SNR)。该技术路径广泛应用于便携式Hi-Res音频设备、USB-C小尾巴DAC及蓝牙高解析耳机放大器等场景。本文围绕ES9038Q2M双模SoC展开,详解其在LDAC协议支持、UAC2.0兼容性及平衡电流型DAC输出方面的工程实现,为高性能、可量产音频硬件开发提供 阅读详情

相关推荐

开关电源环路学习笔记(1)-为啥要知道传递函数?

做硬件都会接触到开关电源,或多或少会接触到环路补偿。很多兄弟们也提出来让我说说这个,说明大家也都很关心,也说明这个好像有点难。 就我个人而言,我也想搞明白环路这一块,也查了一些资料,视频,不过说实话,一直都还是懵的,感觉很困难。 具体感觉就是,看资料或视频的时候,感觉好像是那么回事。但是撇开之后,就又云里雾里的感觉,总有一些想法没有找到答案。 问题 比如下面我想过的问题: 开关电源有开关,根本就不是一个线性系统,传递函数是咋弄出来的? 系统环路框图的输入量为什么不是Vin,而是参考电压V

weixin_42005993的博客 1万+

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

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

程序员充电站(itcharge) 1020

光伏电站发电功率预测实战:从基础物理模型到LSTM时间序列分析

本文系统介绍了光伏电站发电功率预测的实战方法,从基础的物理晴空模型到先进的LSTM时间序列分析。通过结合电工杯等竞赛中常用的代码与模型,详细阐述了如何利用历史数据和数值天气预报构建高精度预测体系,并针对阴雨天气等预测瓶颈提出了分场景建模与模型融合等优化策略,为电站运维和电网调度提供可靠的数据支持。

pp12345的博客 216

【二分图|最小路径覆盖】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

8位可控加减法电路设计

一、设计要求   利用Logisim平台中现有运算部件构建一个8位可控加减法器,可支持八位加减法,利用已经封装全加器和逻辑门进行连接,要求实现相应的输出,判断是否溢出。 二、方案设计 实验原理: [A]补+[B]补 = [A+B]补(mod2^n+1)   公式1        [A-B]补 = [A]补+[-B]补(mod2^n+1)    公式2 FA为全加器,利用全加器实现加减法,难点在于实验减法,对输入的[Y]补各位取反加一即为[-Y]补,利用公式2,就可以将减法转化为加法再利用全加

qq_51700383的博客 1万+

超声波雾化驱动设计:专用芯片FM8118替代MCU的工程实践

超声波雾化是一种基于压电陶瓷谐振原理的高频能量转换技术,其核心在于在1.6–2.4MHz频段精准激励雾化片以实现高效水分子破碎。传统采用通用MCU配合分立MOSFET的方案受限于PWM频率上限、栅极驱动能力不足及EMI控制困难,导致雾化效率低、温升高、可靠性差。专用雾化芯片(如FM8118)通过集成2.1MHz振荡器、零电压开关(ZVS)控制与过流/过热双重保护,从架构层面解决高频功率驱动的本质约束,显著提升驱动效率(达83.7%)与系统鲁棒性。该技术广泛适用于桌面加湿器、医疗雾化器、农业微喷等对体积、功耗

weixin_34620658的博客 405

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

金蝶云苍穹-插件开发(一)加载数据

此系列博客是进行金蝶云苍穹开发时的插件开发的教程,一是在明年要是还要参加软件杯金蝶A6赛题的话,可以看此系列教程的博客来进行复习,同时如果要是我实验室的学弟学妹要参加的话,我这个系列的博客可以给他们提供学习参考,因为插件开发学习的路上很艰难,我学习的时候,能参照的讲解少,要花费大量工夫去猜测去调试才能学会那些语法。在插件开发上,希望我这个系列的博客能帮助到别人。这个系列的博客只专门讲解插件开发,基本的那些金蝶云苍穹的知识点在这里不多作讲解。

二狗mao的博客 3584

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

【OpenClaw企业级智能体实战】第04篇:OpenClaw成本优化实战——Token消耗降96%!claude-mem+OpenViking从入门到精通

OpenClaw作为企业级智能体框架,凭借强大的自动化能力成为企业数字化转型的热门工具,但原生机制导致的上下文冗余问题,让众多用户面临“Token消耗失控”的困境——单周账单数千元的案例屡见不鲜。本文基于阿里云实测数据与开源工具官方文档,先深度拆解OpenClaw成本黑洞的核心成因(记忆碎片化、Token指数级膨胀),再系统讲解两款核心优化工具(claude-mem单Agent记忆管理、OpenViking多Agent集群底座)的底层原理、算法架构与实现逻辑,提供从环境搭建、工具集成、参数调优到安全部署

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 703

CUDA:实现使用cuSolverSP底层API实现Cholesky因式分解(附完整源码)

CUDA:实现使用cuSolverSP底层API实现Cholesky因式分解(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 342

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

手把手教程 | 使用 apktool 修改已发布 APK 的版本号与版本名称

摘要:本文介绍如何使用apktool工具直接修改APK版本信息,适用于版本回滚、多版本测试等场景。详细步骤包括反编译APK、修改版本号、重打包、对齐优化和重新签名,并分享了反编译相关实用知识。该方法无需源代码参与,但需注意修改后的APK必须重新签名才能安装。最后强调应在合法范围内使用反编译技术。

学无止境 826

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

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

Remilia's 1017

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

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

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

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、付费专栏及课程。

余额充值