###### zoj 1654 Place the Robots

！！！构造新图的点的范围 50 * 50

// zoj 1654 Place the Robots
// sf sf sf sf ac 70ms 9164kb
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define FOR(i,a,b) for(i = (a); i < (b); ++i)
#define FORE(i,a,b) for(i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(i = (a); i > (b); --i)
#define FORDE(i,a,b) for(i = (a); i >= (b); --i)
#define CLR(a,b) memset(a,b,sizeof(a))
#define PB(x) push_back(x)

const int MAXN = 55;

bool g[MAXN * MAXN][MAXN * MAXN];
int n, m, t;
int cntx, cnty, ans, cas = 1;
int posx[MAXN][MAXN], posy[MAXN][MAXN];
int result[MAXN * MAXN];
bool state [MAXN * MAXN];
char tu[MAXN][MAXN];

void create() {
int i, j, l;

FOR(i, 0, n) {
j = 0;
while(j < m) {
if(tu[i][j] == 'o') {
++cntx;
while(j < m && tu[i][j] != '#')
posx[i][j++] = cntx;
}
else
++j;
}
}
FOR(j, 0, m) {
i = 0;
while(i < n) {
if(tu[i][j] == 'o') {
++cnty;
while(i < n && tu[i][j] != '#')
posy[i++][j] = cnty;
}
else
++i;
}
}
FOR(i, 0, n) FOR(j, 0, m) if(tu[i][j] == 'o')
g[posx[i][j]][posy[i][j]] = true;
}

void init() {
int i;

CLR(g, false);
CLR(posx, 0);
CLR(posy, 0);
CLR(result, 0);
ans = cntx = cnty = 0;
scanf("%d %d", &n, &m);
FOR(i, 0, n)
scanf("%s", tu[i]);
}

bool find(int a) {
int i;

FORE(i, 1, cnty) {
if (g[a][i] && !state[i]) {
state[i] = true;
if (result[i] == 0 || find(result[i])) {
result[i] = a;
return true;
}
}
}
return false;
}

void solve() {
int i;

create();
FORE(i, 1, cntx) {
CLR(state, false);
if (find(i))
++ans;
}
printf("Case :%d\n", cas++);
printf("%d\n", ans);
}

int main() {
scanf("%d", &t);
while(t--) {
init();
solve();
}
return 0;
}


#### ZOJ1654.Place the Robots放置机器人——最大独立集

2015-03-18 13:40:31

#### ZOJ 1654 Place the Robots

2014-07-17 18:33:33

#### Place the Robots zoj 1654

2013-11-06 10:41:56

#### zoj 1654 Place the Robots

2011-02-27 23:36:00

#### ZOJ 1654 Place the Robots【二分图匹配】

2016-03-27 19:11:42

#### zoj 1654 Place the Robots （二分图匹配）

2013-06-12 17:36:40

#### zoj 1654 Place the Robots 最大匹配

2011-09-21 08:48:36

#### ZOJ 1654 Place the Robots（最大二分匹配）

2011-03-19 12:41:00

#### 【二分匹配】ZOJ 1654 Place the Robots

2014-08-12 10:49:27

#### zoj 1654 Place the Robots 二分图匹配

2014-08-17 18:59:52

## 不良信息举报

zoj 1654 Place the Robots