define     n    the number of  ' * '

define     d    the number of couple of two points

define     s    the single point that can't link to others ( means no points around it in 4 directions )

n = 2 * d + s ;

d + s = n - d

use Hungary finding out the d

 #include <stdio.h>
#include <string.h>
char gird[][];
int number[][];
int graph[][];
int in[];
int already[];
int cnt; struct node{
int x,y;
}p[];
int dir[][]={ ,,,-,-,,,}; int find(int a){
int i;
for(i=;i<cnt;++i){
if( graph[a][i]== && in[i]== ){
in[i]=;
if( already[i]==- || find( already[i] )){
already[i]=a;
return ;
}
}
}
return ;
} int main(){
int t;
int n,m,i,j;
int tx,ty,tnum;
int res;
while(~scanf("%d",&t)){
while(t--){
res=;
cnt=;
memset(in,,sizeof(in));
memset(graph,,sizeof(graph));
for(i=;i<;++i) already[i]=-;
scanf("%d%d",&n,&m);
for(i=;i<n;++i){
scanf("%s",gird[i]);
for(j=;j<m;++j)
if(gird[i][j]=='*'){
number[i][j]=cnt;
p[cnt].x=i;
p[cnt].y=j;
cnt++;
}
}
for(i=;i<cnt;++i){
for(j=;j<;++j){
tx=p[i].x+dir[j][];
ty=p[i].y+dir[j][];
if((!(tx>=&&tx<n&&ty>=&&ty<m))||gird[tx][ty]!='*') continue;
tnum=number[tx][ty];
graph[i][tnum]=;
}
}
for(i=;i<cnt;++i){
memset(in,,sizeof(in));
if(find(i)==)
res++;
}
printf("%d\n",cnt-res/);
}
}
return ;
}

poj3020的更多相关文章

  1. 【poj3020】 Antenna Placement

    http://poj.org/problem?id=3020 (题目链接) 题意 给出一个矩阵,矩阵中只有‘*’和‘o’两种字符,每个‘*’可以向它上下左右四个方位上同为‘*’的点连一条边,求最少需要 ...

  2. POJ3020——Antenna Placement(二分图的最大匹配)

    Antenna Placement DescriptionThe Global Aerial Research Centre has been allotted the task of buildin ...

  3. poj3020 Antenna Placement 匈牙利算法求最小覆盖=最大匹配数(自身对应自身情况下要对半) 小圈圈圈点

    /** 题目:poj3020 Antenna Placement 链接:http://poj.org/problem?id=3020 题意: 给一个由'*'或者'o'组成的n*m大小的图,你可以用一个 ...

  4. POJ-3020 Antenna Placement---二分图匹配&最小路径覆盖&建图

    题目链接: https://vjudge.net/problem/POJ-3020 题目大意: 一个n*m的方阵 一个雷达可覆盖两个*,一个*可与四周的一个*被覆盖,一个*可被多个雷达覆盖问至少需要多 ...

  5. POJ3020 Antenna Placement —— 最大匹配 or 最小边覆盖

    题目链接:https://vjudge.net/problem/POJ-3020 Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K ...

  6. 二分图之最小边覆盖(poj3020)

    题目:poj3020 题意:给出一个图,让你用最少的1*2的纸片覆盖掉图中的全部*出现过的地方. 基本裸的最小边覆盖. 分析: 最小边覆盖 = 点总数 - 最大匹配 所以就是转化为求最大匹配. 跟前面 ...

  7. POJ3020 匹配

    题目大意:给定一地图,*可以和相邻的*匹配成一对儿,问最少需要对儿匹配才能使所有*都被匹配到. 很直白的最小点覆盖,即ans = 点集数-最大匹配数. 不过一开始要对图进行遍历得到点集,找到一个*就把 ...

  8. hdu4185+poj3020(最大匹配+最小边覆盖)

    传送门:hdu4185 Oil Skimming 题意:n*n的方格里有字符*和#,只能在字符#上放1*2的板子且不能相交,求最多能放多少个. 分析:直接给#字符编号,然后相邻的可以匹配,建边后无向图 ...

  9. poj3020二分图匹配

    The Global Aerial Research Centre has been allotted the task of building the fifth generation of mob ...

随机推荐

  1. JadClipse eclipse反编译插件

    A.下载JadClipse,http://jadclipse.sourceforge.net/wiki/index.php/Main_Page#Download,注意选择与eclipse版本一致的版本 ...

  2. phpStudy Linux安装集成环境 (CentOS--7)

    phpStudy for Linux (lnmp+lamp一键安装包) phpStudy for Linux 支持Apache/Nginx/Tengine/Lighttpd, 支持php5.2/5.3 ...

  3. ConcurrentHashMap使用要点

    ConcurrentHashMap的简要总结: 1.public V get(Object key)不涉及到锁,也就是说获得对象时没有使用锁: 2.put.remove方法要使用锁,但并不一定有锁争用 ...

  4. ubuntu vnc install

    windows & ubuntu http://www.jb51.net/os/Ubuntu/104948.html ubuntu & ubuntu https://www.digit ...

  5. ddl语句

  6. Gatling的进阶二

    1. 参数化     Gatling可以很方便使用csv文件进行参数化,例如一个用户信息表:   /* user_information.csv */ username,password,accoun ...

  7. zabbix入门到精通之Zabbix对linux主机的监控

    我们大概了解了怎么对台主机进行监控,主要步骤设计到添加主机,并且为主机添加监控项,这里主要为item,然后在item的基础上对item进行绘图并且通过screen的方式把不同的监控图像汇总到一张scr ...

  8. Aspose.Cells单元格转换为数字格式

    需要在两个地方设置 //Adding a numeric value to "A2" cell "; worksheet.Cells["A2"].Pu ...

  9. VB6的命令行参数

    在DOS窗口下执行如下命令: C:\Program Files\Microsoft Visual Studio\VB98>vb6 /?

  10. poj 1459 Power Network : 最大网络流 dinic算法实现

    点击打开链接 Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 20903   Accepted:  ...