Leapin' Lizards

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3488    Accepted Submission(s): 1439

Problem Description
Your platoon of wandering lizards has entered a strange room in the labyrinth you are exploring. As you are looking around for hidden treasures, one of the rookies steps on an innocent-looking stone and the room's floor suddenly disappears! Each lizard in your platoon is left standing on a fragile-looking pillar, and a fire begins to rage below... Leave no lizard behind! Get as many lizards as possible out of the room, and report the number of casualties.
The pillars in the room are aligned as a grid, with each pillar one unit away from the pillars to its east, west, north and south. Pillars at the edge of the grid are one unit away from the edge of the room (safety). Not all pillars necessarily have a lizard. A lizard is able to leap onto any unoccupied pillar that is within d units of his current one. A lizard standing on a pillar within leaping distance of the edge of the room may always leap to safety... but there's a catch: each pillar becomes weakened after each jump, and will soon collapse and no longer be usable by other lizards. Leaping onto a pillar does not cause it to weaken or collapse; only leaping off of it causes it to weaken and eventually collapse. Only one lizard may be on a pillar at any given time.

Input
The input file will begin with a line containing a single integer representing the number of test cases, which is at most 25. Each test case will begin with a line containing a single positive integer n representing the number of rows in the map, followed by a single non-negative integer d representing the maximum leaping distance for the lizards. Two maps will follow, each as a map of characters with one row per line. The first map will contain a digit (0-3) in each position representing the number of jumps the pillar in that position will sustain before collapsing (0 means there is no pillar there). The second map will follow, with an 'L' for every position where a lizard is on the pillar and a '.' for every empty pillar. There will never be a lizard on a position where there is no pillar.Each input map is guaranteed to be a rectangle of size n x m, where 1 ≤ n ≤ 20 and 1 ≤ m ≤ 20. The leaping distance is
always 1 ≤ d ≤ 3.

Output
For each input case, print a single line containing the number of lizards that could not escape. The format should follow the samples provided below.

Sample Input
4 3 1 1111 1111 1111 LLLL LLLL LLLL 3 2 00000 01110 00000 ..... .LLL. ..... 3 1 00000 01110 00000 ..... .LLL. ..... 5 2 00000000 02000000 00321100 02000000 00000000 ........ ........ ..LLLL.. ........ ........

Sample Output
Case #1: 2 lizards were left behind. Case #2: no lizard was left behind. Case #3: 3 lizards were left behind. Case #4: 1 lizard was left behind.

Source

Recommend
zty   |   We have carefully selected several similar problems for you:  3338 1533 3416 1569 2883

2、源点和存在蜥蜴的点i连，权值为1。

3,、如果该点i’能直接出界则与汇点连接权值为INF，否则连接它能达到的点j

#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/hash_set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define XINF INT_MAX
#define INF 0x3F3F3F3F
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
#define RIT reverse_iterator
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
typedef tree<PII, null_type, greater<PII>, rb_tree_tag, tree_order_statistics_node_update > rb_tree_set;
typedef tree<PII, PII, greater<PII>, rb_tree_tag, tree_order_statistics_node_update > rb_tree;
#define PQ std::priority_queue
#define HEAP __gnu_pbds::priority_queue
#define X first
#define Y second
#define lson(X) ((X)<<1)
#define rson(X) ((X)<<1|1)
#define N 100
#define M 100000
char mapt1[N][N];
char mapt2[N][N];
int n, m, k;
int src, des;
struct Edeg
{
queue <int> q;
int g[N*N*2], nt[M], vt[M], c[M], ec;
int cur[N*N*2], lev[N*N*2];
inline void init() {
ec = 1;
memset(g, 0 ,sizeof(g));
}
inline void addedge(int x, int y ,int cap) {
nt[++ec] = g[x]; g[x] = ec; vt[ec] = y; c[ec] = cap;
nt[++ec] = g[y]; g[y] = ec; vt[ec] = x; c[ec] = 0;
}
inline bool bfs() {
while(!q.empty()) q.pop();
memset(lev, 0, sizeof(lev));
lev[src] = 1;
q.push(src);
while(!q.empty()) {
int u = q.front();
q.pop();
for(int e = g[u]; e; e = nt[e]) {
if(!c[e]||lev[vt[e]])	continue;
lev[vt[e]] = lev[u] + 1;
q.push(vt[e]);
if(vt[e] == des)
return true;
}
}
return false;
}
inline int dinic(int x, int f) {
if(x == des)	return f;
int rs = 0;
for(int &e = cur[x]; e; e = nt[e]) {
if(!c[e] || lev[vt[e]]!=lev[x]+1)
continue;
int flow = dinic(vt[e], min(f-rs, c[e]));
c[e] -= flow;
c[e^1] += flow;
rs += flow;
if(rs <= 0) {
int t;
}
if(rs == f)
return rs;
}

return lev[x] = 0, rs;
}
inline int maxflow() {
int rs = 0;
while(bfs()) {
int tt;
memcpy(cur, g, sizeof(cur));
while((tt=dinic(src, INF)))
rs+=tt, memcpy(cur, g, sizeof(cur));

}
return rs;
}
}G;

int main()
{
int T;
scanf("%d",&T);
int Case = 1;
while(T--) {
scanf("%d%d",&n, &k);
G.init();
for(int i = 1; i <= n; i++) {
scanf("%s", mapt1[i]+1);
m = strlen(mapt1[i]+1);
for(int j = 1; j <= m; j++) {
}
}
int ans = 0;
src = 0, des = n*m*2+1;
for(int i = 1; i <= n; i++) {
scanf("%s", mapt2[i]+1);
for(int j = 1; j <= m;j ++) {
if(mapt2[i][j] == 'L') {
ans ++;
}
}
}
for(int i = 1; i <= n ;i++) {
for(int j = 1; j <= m; j++) {
if(mapt1[i][j]-'0' == 0)
continue;
if(i-k<=0 || i+k>n || j-k<=0|| j+k > m)
else {
for(int x = 1 ; x <= n; x++) {
for(int y = 1; y <= m; y++) {
if(mapt1[x][y] == '0')
continue;
if(x==i&&y==j)
continue;
if(abs(x-i)+abs(y-j)<=k)
}
}
}
}
}
int t = ans - G.maxflow();
if(t == 0) {
printf("Case #%d: no lizard was left behind.\n", Case++);
}else if(t == 1) {
printf("Case #%d: 1 lizard was left behind.\n", Case++);
}else {
printf("Case #%d: %d lizards were left behind.\n", Case++, t);
}
}
return 0;
}


• 本文已收录于以下专栏：

举报原因： 您举报文章：hdu 2732Leapin' Lizards 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)