Air Raid

2023-11-15

http://poj.org/problem?id=1422

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 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
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
求出来的DFS()实际上是二分图的最大匹配边数;n个点减掉最大匹配的边,剩下的就是需要投多少士兵在上边就行了,匹配边上需要放士兵,但只需要在匹配边的2端,只一端放就行了,另外的人放到n-2*DFS()上,所以需要放的士兵总数为n-2*DFS()+DFS()=n-DFS();
#include<stdio.h>
#include<string.h>
int map[200][200],link[200],vist[200];
int m,n;
int find(int u)
{
	int i,j,k;
	for(i=1;i<=n;i++)
	{
		if(!vist[i]&&map[u][i])
		{
			vist[i]=1;
			if(!link[i]||find(link[i]))
			{
				link[i]=u;
				return 1;
			}
		}
	}
	return 0;
}
int DFS()
{
	int i,j,k,ans=0;
	memset(link,0,sizeof(link));
	for(i=1;i<=n;i++)
	{
		memset(vist,0,sizeof(vist));
		if(find(i))
	    	ans++;
	}
	return ans;
}
int main()
{
	int i,j,k,ncase,a,b;
	scanf("%d",&ncase);
	while(ncase--)
	{
		scanf("%d%d",&n,&m);
		memset(map,0,sizeof(map));
		while(m--)
		{
			scanf("%d%d",&a,&b);
			map[a][b]=1;
		}
		printf("%d\n",n-DFS());
	}
	return 0;
}




本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Air Raid 的相关文章

  • 如何生成满足某些限制的整数?

    任何人都可以帮我提供生成满足某些限制的整数的技术吗 例如 假设我需要生成整数 x 和 y 使得 100 gt x and y lt x 5 我指的并不是这个特定的示例 而是一些生成满足某些条件的整数的通用技术 嗯 这并不难 选择一个整数 可
  • 过滤(搜索和替换)InputStream 中的字节数组

    我有一个 InputStream 它将 html 文件作为输入参数 我必须从输入流中获取字节 我有一个字符串 XYZ 我想将此字符串转换为字节格式 并检查从 InputStream 获得的字节序列中是否存在与该字符串匹配的字符串 如果有的话
  • 使用 JavaScript 或 jQuery 设置文本框的最大长度

    我想用 JavaScript 或 jQuery 更改文本框的最大长度 我尝试了以下方法 但似乎没有帮助 var a document getElementsByTagName input for var i 0 i
  • 如何对无法存储在一个变量中的大数字进行运算

    在Java中 我希望能够对非常大的整数 不能存储在long中 进行操作 我该怎么做 在表现良好的情况下 处理这个问题的最佳方法是什么 我应该创建自己的包含多个长变量的数据类型吗 Example public class MyBigInteg
  • Ionic 2 获取离子输入值

    我正在使用 ionic 2 创建登录名 请不要只回答 您只需要添加 ngModules 属性 如果您认为这就是解决方案 请解释原因 解释一下 就像对孩子做的那样 我的代码在login ts import Component from ang
  • 为什么 textarea 不是 input[type="textarea"]?

    为什么有一个元素
  • 推送通知需要很长时间才能到达

    我在适用于 iOS 和 Android 的 Adob e Air 应用程序中遇到推送通知的奇怪问题 我正在使用 Milkman Games 的 Easy Push ANE 以及 One Signal 服务 问题是通知确实会到达 但有时 随机
  • Adobe AIR 应用程序能否实现针对 Active Directory 的 SSO 身份验证?

    我对 AIR 应用程序了解不多 但我喜欢目前所看到的内容 所以现在 我想知道这种类型的应用程序在工作中的内联网中是否有意义 在投入时间和精力加强 AIR 开发之前 我想知道 Windows 上的 AIR 应用程序是否可以针对 Active
  • 正则表达式查找字符串中的整数和小数

    我有一个像这样的字符串 str1 12 ounces str2 1 5 ounces chopped 我想从字符串中获取金额 无论它是否是小数 12 或 1 5 然后获取紧邻的前一个测量值 盎司 我能够使用一个非常基本的正则表达式来获取测量
  • 如何同时接受int和float类型的输入?

    我正在制作一个货币转换器 如何让 python 同时接受整数和浮点数 我就是这样做的 def aud brl amount From to ER 0 42108 if amount int if From strip aud and to
  • 解析输入,除了 System.in.read() 之外不使用任何东西

    我很难找到具体的细节System in read 有效 也许有人可以帮助我 似乎扫描仪会更好 但我不允许使用它 我被分配了一个任务 我应该以 Boolean Operator Boolean 的形式读取控制台用户输入 例如T F 或 T T
  • Android键盘点击搜索输入时出现和消失

    我在用谷歌地图 Js API当我搜索一个地方时 我的输入搜索栏工作正常 当我通过 iPhone 设备使用它时 它也工作得很好 但是当我通过Android 设备然后键盘立即出现和消失 我已经找到了一些关于当我按下搜索栏时 android 键盘
  • 如何使用文本输入来定位?

    我想使用 jQuery 通过文本框转到锚点 例如 我想使用以下形式
  • 使用
    元素作为 JavaScript 代码的输入。这是最好的方法吗?

    各位 显然 我是编码新手 所以最近完成了一些有关 HTML 和 Javascript 的 Lynda 课程后 我的简单 HTML 页面遇到了困难 基本上 我想要的是使用 JavaScript 进行基本计算 让用户使用 HTML 输入两个数字
  • 如何使用 JS/Puppeteer 上传文件

    我试图弄清楚如何将图片文件上传到输入对话框中 不可能只输入名称并按 Enter 键 因为我没有找到使用 Puppeteer 实现自动化的方法 我想我必须设置一些值作为图片 但我不知道该怎么做 有任何想法吗 您使用上传文件elementHan
  • 整数除法性质

    下面的整数算术性质成立吗 m n l m n l 起初我以为我知道答案 不成立 但现在不确定 它适用于所有数字还是仅适用于某些条件 即n gt l 该问题涉及计算机算术 即q n m q m n 忽略溢出 Case1 assume m kn
  • Solr 不搜索整数?

    我目前正在使用 Solr 为电子商务网站开发搜索引擎 所以我在 schema xml 中得到这两个字段
  • 解析dev/input/event触摸事件

    我能够在 Android 手机上从 dev input event 读取事件 然而 它们是按一定顺序排列的行代码 就像触摸事件给出的那样 3 53 216 3 54 444 3 48 40 3 50 5 0 2 0 0 0 0 如何将它们解
  • 如何将 C# 与 AIR 结合使用?

    我在制作 Flex 网站方面有一些基本经验 但我认为 Flex 在制作桌面 AIR 应用程序方面更有用 无论如何 我想知道是否至少可以将 C 与 Actionscript AIR 一起使用 我找不到任何这方面的例子 另外 我可以在 Flex
  • 存储整数列表的最有效方法

    我最近一直在做一个项目 其中一个目标是使用尽可能少的内存来使用 Python 3 存储一系列文件 除了一个整数列表之外 几乎所有文件都占用很少的空间 大致333 000整数长且整数可达约8000在尺寸方面 我目前正在使用pickle存储列表

随机推荐