BNUOJ 1541 Air Raid
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了BNUOJ 1541 Air Raid,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3751字,纯文字阅读大概需要6分钟。
内容图文
![BNUOJ 1541 Air Raid](/upload/InfoBanner/zyjiaocheng/1270/7f8e5685a4fe4fcb98fd1259f9e13b38.jpg)
Air Raid
64-bit integer IO format: %lld Java class name: Main
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
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
Sample Input
2 4 3 3 4 1 3 2 3 3 3 1 3 1 2 2 3
Sample Output
2 1
Source
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13#define LL long long 14#define pii pair<int,int> 15#define INF 0x3f3f3f3f 16usingnamespace std; 17constint maxn = 200; 18int mp[maxn][maxn],from[maxn],n,m; 19bool vis[maxn]; 20bool dfs(int u){ 21for(int v = 1; v <= n; v++){ 22if(mp[u][v] && !vis[v]){ 23 vis[v] = true; 24if(from[v] == -1 || dfs(from[v])){ 25from[v] = u; 26returntrue; 27 } 28 } 29 } 30returnfalse; 31} 32int main() { 33int t,u,v,ans,i; 34 scanf("%d",&t); 35while(t--){ 36 scanf("%d %d",&n,&m); 37 memset(mp,0,sizeof(mp)); 38 memset(from,-1,sizeof(from)); 39for(i = 0; i < m; i++){ 40 scanf("%d %d",&u,&v); 41 mp[u][v] = 1; 42 } 43 ans = 0; 44for(i = 1; i <= n; i++){ 45 memset(vis,false,sizeof(vis)); 46if(dfs(i)) ans++; 47 } 48 printf("%d\n",n-ans); 49 } 50return0; 51 }
原文:http://www.cnblogs.com/crackpotisback/p/3907251.html
内容总结
以上是互联网集市为您收集整理的BNUOJ 1541 Air Raid全部内容,希望文章能够帮你解决BNUOJ 1541 Air Raid所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。