poj3020
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的更多相关文章
- 【poj3020】 Antenna Placement
http://poj.org/problem?id=3020 (题目链接) 题意 给出一个矩阵,矩阵中只有‘*’和‘o’两种字符,每个‘*’可以向它上下左右四个方位上同为‘*’的点连一条边,求最少需要 ...
- POJ3020——Antenna Placement(二分图的最大匹配)
Antenna Placement DescriptionThe Global Aerial Research Centre has been allotted the task of buildin ...
- poj3020 Antenna Placement 匈牙利算法求最小覆盖=最大匹配数(自身对应自身情况下要对半) 小圈圈圈点
/** 题目:poj3020 Antenna Placement 链接:http://poj.org/problem?id=3020 题意: 给一个由'*'或者'o'组成的n*m大小的图,你可以用一个 ...
- POJ-3020 Antenna Placement---二分图匹配&最小路径覆盖&建图
题目链接: https://vjudge.net/problem/POJ-3020 题目大意: 一个n*m的方阵 一个雷达可覆盖两个*,一个*可与四周的一个*被覆盖,一个*可被多个雷达覆盖问至少需要多 ...
- POJ3020 Antenna Placement —— 最大匹配 or 最小边覆盖
题目链接:https://vjudge.net/problem/POJ-3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K ...
- 二分图之最小边覆盖(poj3020)
题目:poj3020 题意:给出一个图,让你用最少的1*2的纸片覆盖掉图中的全部*出现过的地方. 基本裸的最小边覆盖. 分析: 最小边覆盖 = 点总数 - 最大匹配 所以就是转化为求最大匹配. 跟前面 ...
- POJ3020 匹配
题目大意:给定一地图,*可以和相邻的*匹配成一对儿,问最少需要对儿匹配才能使所有*都被匹配到. 很直白的最小点覆盖,即ans = 点集数-最大匹配数. 不过一开始要对图进行遍历得到点集,找到一个*就把 ...
- hdu4185+poj3020(最大匹配+最小边覆盖)
传送门:hdu4185 Oil Skimming 题意:n*n的方格里有字符*和#,只能在字符#上放1*2的板子且不能相交,求最多能放多少个. 分析:直接给#字符编号,然后相邻的可以匹配,建边后无向图 ...
- poj3020二分图匹配
The Global Aerial Research Centre has been allotted the task of building the fifth generation of mob ...
随机推荐
- Java多线程之简单的线程同步实例
数据类: package Thread.MyCommon; public class Data { public int num = 0; public synchronized int getEve ...
- 30天轻松学习javaweb_Range实现断点续传
package com.wzh.test.http; import java.io.FileOutputStream; import java.io.IOException; import java. ...
- 集成paypal支付
https://developer.paypal.com cocoapods 管理 引入 pod 'PayPal-iOS-SDK' 1.在appdelegate #import <PayPalM ...
- git简单使用和说明文件的书写
一. git 简单使用 1.注册 https://github.com/ 2.初始化 配置 git config --global user.name "Your Name" gi ...
- HTMLParser使用详解(3)- 通过Filter访问内容
HTMLParser遍历了网页的内容以后,以树(森林)结构保存了结果.HTMLParser访问结果内容的方法有两种.使用Filter和使用Visitor. (一)Filter类顾名思义,Filter就 ...
- rails4.2.6配置发送邮件
调试了很久,最后终于可以发送了 1 在config/environments/development.rb文件里配置邮件信息 config.action_mailer.raise_delivery_e ...
- plsql如果表和函数等显示不出来
就把用户设为所有用户,所有的东西就会都显示出来了,然后再把用户切换为当前用户和My objects,你想看的东西就全部显示出来了.
- [ActionScript 3.0] AS3动态改变注册点
package { import flash.display.DisplayObject; import flash.display.DisplayObjectContainer; import fl ...
- [ActionScript3.0] 逻辑或"||=" ,等于"=="和全等于"==="
function a(o:Object):void { o||=new Object(); trace(o); } //此上下两个方法作用是一样的 function b(o:Object):void ...
- char 汉字
Unicode/UCS总结: UCS和Unicode使用最大32bit来表示字符(它的范围很大,但不一定全使用,常使的是UCS-2),它用2~4个字节的空间描述了已知的接近全部的字符(并且仍在更新,还 ...