(重)POJ 3020Antenna Placement
http://poj.org/problem?id=3020
呃。。。这个题不是很会,所以找了大神的博客做了参考,说得很详细
http://blog.csdn.net/lyy289065406/article/details/6647040
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std ;
const int maxn = ;
int map[maxn][maxn] ;
int ID ;
int v1,v2 ;
int ma ;
bool city[maxn][maxn] ;
bool vist[maxn] ;
int link[maxn] ;
int dirr[] = {-,,,} ;
int dirc[] = {,,-,} ;
bool dfs(int x)
{
for(int i = ; i <= v2 ; i++)
{
if(city[x][i] && !vist[i])
{
vist[i] = true ;
if(link[i] == || dfs(link[i]))
{
link[i] = x ;
return true ;
}
}
}
return false ;
}
void sea()
{
for(int i = ; i <= v1 ; i++)
{
memset(vist, ,sizeof(vist)) ;
if(dfs(i))
ma++ ;
}
return ;
}
int main()
{
int t ;
scanf("%d",&t) ;
while(t--)
{
memset(map,,sizeof(map)) ;
memset(city,,sizeof(city)) ;
memset(link,,sizeof(link)) ;
ID = ;
ma = ;
int h,w ;
scanf("%d %d",&h,&w) ;
char temp ;
for(int i = ; i <= h ; i++)
{
for(int j = ; j <= w ; j++)
{
cin>>temp ;
if(temp == '*')
map[i][j] = ++ ID ;
}
}
for(int i = ; i <= h ; i++)
{
for(int j = ; j <= w ; j++)
{
if(map[i][j])
{
for(int k = ; k < ; k++)
{
int x = i+dirr[k] ;
int y = j+dirc[k] ;
if(map[x][y])
city[map[i][j]][map[x][y]] = true ;
}
}
}
}
v1 = v2 = ID ;
sea() ;
printf("%d\n",ID-ma/) ;
}
return ;
}
(重)POJ 3020Antenna Placement的更多相关文章
- poj 3020Antenna Placement
http://poj.org/problem?id=3020 #include<cstdio> #include<cstring> #include<algorithm& ...
- POJ:3020-Antenna Placement(二分图的最小路径覆盖)
原题传送:http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Descri ...
- poj 3020 Antenna Placement(最小路径覆盖 + 构图)
http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- poj 2762 Going from u to v or from v to u?(强连通分量+缩点重构图+拓扑排序)
http://poj.org/problem?id=2762 Going from u to v or from v to u? Time Limit: 2000MS Memory Limit: ...
- (poj)3020 Antenna Placement 匹配
题目链接 : http://poj.org/problem?id=3020 Description The Global Aerial Research Centre has been allotte ...
- POJ 1170 Shopping Offers -- 动态规划(虐心的六重循环啊!!!)
题目地址:http://poj.org/problem?id=1170 Description In a shop each kind of product has a price. For exam ...
- poj 1564 Sum It Up | zoj 1711 | hdu 1548 (dfs + 剪枝 or 判重)
Sum It Up Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Sub ...
- POJ 1475 Pushing Boxes 搜索- 两重BFS
题目地址: http://poj.org/problem?id=1475 两重BFS就行了,第一重是搜索箱子,第二重搜索人能不能到达推箱子的地方. AC代码: #include <iostrea ...
- POJ 3020 Antenna Placement【二分匹配——最小路径覆盖】
链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
随机推荐
- Office365 InfoPath 表单的设计和应用(原创)
表单的应用:我想到的有2种. 1 做为自定义表单库的模版. 通过发放url(模版链接)给用户来填写表单. 最后将在表单库中得到所有填写的信息列表. 如 2 上传表单做为ContentType 也就是自 ...
- XML DOM操作,适用目前流行的浏览器
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- 接口和抽象类:Interface、abstract _【转】
一.接口 接口是C#中很常见的工具,概念什么的就不说了,这里讲几个值得注意的小地方: 1.接口内部只能有函数.属性和事件的声明: interface IParent { void Show(); st ...
- iOS 各种控件默认高度
1.状态栏 状态栏一般高度为20像素,在打手机或者显示消息时会放大到40像素高,注意,两倍高度的状态栏在好像只能在纵向的模式下使用.如下图 用户可以隐藏状态栏,也可以将状态栏设置为灰色,黑色或者半 ...
- string和stringbuilder
1)String是一个引用类型,一旦字符串被创建,就不能修改 例如: String a="AAA"; String b=a; a与b值相同,但不是同一个对象: 每次使用 Syste ...
- 【html】【18】高级篇--下拉列表[竖向手风琴]
下载: http://sc.chinaz.com/jiaoben/141027501240.htm html: <!DOCTYPE html> <html> <head ...
- C# 高精度求幂 poj1001
高精度求幂 public static char[] exponentiation(string a,int r) { ]; string b = ""; string c = a ...
- C#构造函数相关主题
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- MVC开发 好的扩展套件(Visual Studio 插件)
- 九度OJ 1385 重建二叉树
题目地址:http://ac.jobdu.com/problem.php?pid=1385 题目描述: 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都 ...