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的更多相关文章

  1. poj 3020Antenna Placement

    http://poj.org/problem?id=3020 #include<cstdio> #include<cstring> #include<algorithm& ...

  2. POJ:3020-Antenna Placement(二分图的最小路径覆盖)

    原题传送:http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Descri ...

  3. poj 3020 Antenna Placement(最小路径覆盖 + 构图)

    http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  4. 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:  ...

  5. (poj)3020 Antenna Placement 匹配

    题目链接 : http://poj.org/problem?id=3020 Description The Global Aerial Research Centre has been allotte ...

  6. POJ 1170 Shopping Offers -- 动态规划(虐心的六重循环啊!!!)

    题目地址:http://poj.org/problem?id=1170 Description In a shop each kind of product has a price. For exam ...

  7. 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 ...

  8. POJ 1475 Pushing Boxes 搜索- 两重BFS

    题目地址: http://poj.org/problem?id=1475 两重BFS就行了,第一重是搜索箱子,第二重搜索人能不能到达推箱子的地方. AC代码: #include <iostrea ...

  9. POJ 3020 Antenna Placement【二分匹配——最小路径覆盖】

    链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

随机推荐

  1. dirname(__FILE__) 的使用总结

    dirname(__FILE__) php中定义了一个很有用的常数,即 __file__ 这个内定常数是当前php程序的就是完整路径(路径+文件名). 即使这个文件被其他文件引用(include或re ...

  2. 创建image对象

    Image是一个抽象列,BufferedImage是Image的实现. Image和BufferedImage的主要作用就是将一副图片加载到内存中. Java将一副图片加载到内存中的方法是: Stri ...

  3. 第二十三篇、使用NSURLSession时需要注意一个内存泄漏问题

    如图1代码所示,初始化一个NSURLSession临时实例对象并由它发起一个网络请求.我们通过Instruments的Leaks工具会发现其存在内存泄漏和循环引用的地方,如图2所示. 通过NSURLS ...

  4. 崩溃信息:Message from debugger: Terminated due to signal 9

    是因为你在调试的时候主动了结束了程度,如上滑结束了程序

  5. 【开发】Dialog 对话框

    提示:Dialog 继承自 Panel,有大量的方法在 Panel 中已被定义,可以复用. Dialog API:http://www.jeasyui.net/plugins/181.html Pan ...

  6. Linux Terminal命令

    Linux Terminal命令 1.Ctrl + a 回到命令行の「行首/head」. 2.Ctrl + e 回到命令行の「行尾/tail」, ctrl + end. 3.Ctrl + w 後向/b ...

  7. 暑假集训(2)第八弹 ----- Hero(hdu4310)

    K - Hero Crawling in process... Crawling failed Time Limit:3000MS     Memory Limit:65536KB     64bit ...

  8. starling 中 的特效

    一. 最好用同一张图片进行缩放变形等处理后组合,这样可以每帧一draw

  9. linux中的sticky bit

    今天看到有个目录的权限是rwxrwxrwt 很惊讶这个t是什么,怎么不是x或者-呢?搜了下发现: 这个t代表是所谓的sticky bit. sticky bit: 该位可以理解为防删除位. 一个文件是 ...

  10. 《APUE》第四章笔记(2)

    下面介绍对stat结构的各个成员的操作函数. 先贴个stat结构的图: access函数: #include <unistd.h> int access(const char *pathn ...