hdu 2732Leapin' Lizards

原创 2018年04月15日 22:30:55

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 

题意:有n行,没有告诉你多少列,一直蜥蜴最多能跳d远,d这个距离指的是 abs(x1-x2)+abs(y1-y2)。每个点都有一个耐久度digit(0-3),蜥蜴跳一次就减少一次耐久度,‘L’代表该点有一个蜥蜴。

网络流,建图:1、将每个点拆成i和i’连一条边权值为柱子的耐久度。

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

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

权值为INF。


#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++) {
				G.addedge(m*(i-1)+j, (i-1)*m+n*m+j, mapt1[i][j]-'0');
			}
		}
		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 ++;
					G.addedge(src,(i-1)*m+j, 1);
				}
			}
		}
		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)
					G.addedge((i-1)*m+n*m+j, des, INF);
				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)
								G.addedge((i-1)*m+n*m+j, (x-1)*m+y, INF);
						}
					}
				}
			}
		}
		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;
}




版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37785469/article/details/79954445

Leapin' Lizards (hdu 2732 最大流)

题意:给一个n行的图(不知道有多少列),每个点的数字表示能承受的最大跳跃次数,接下来又是n行,‘L’表示蜥蜴所在地方,给出蜥蜴能跳跃的最大距离d,每次蜥蜴跳离的那根柱子的承受力会减一,若为零了该点的柱...
  • u014422052
  • u014422052
  • 2015年04月18日 21:50
  • 711

HDU2732Leapin' Lizards(最大流SAP,建图---折点法)

Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)...
  • u010372095
  • u010372095
  • 2015年06月12日 17:04
  • 788

HDU 2732 Leapin' Lizards(最大流)

HDU 2732 Leapin' Lizards(最大流) http://acm.hdu.edu.cn/showproblem.php?pid=2732 题意:        给你一个网格,网格上的一...
  • u013480600
  • u013480600
  • 2014年08月31日 22:21
  • 1181

【HDU】 2732 Leapin' Lizards

Leapin’ Lizards题目链接 Leapin’Lizards 题目大意 给你两个图,一个用0,1,2,3表示,一个用 L 或 . 表示。其中用L表示的图中,有L的位置表示有蜥蜴,没有L的位...
  • S_Black
  • S_Black
  • 2016年05月06日 16:20
  • 604

HDU--杭电--2732//POJ--2711--Leapin' Lizards--网络流

Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)...
  • hncu1206401liuhao
  • hncu1206401liuhao
  • 2015年06月14日 05:55
  • 701

hdu2732 最大流~

Leapin' Lizards Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...
  • JustSteps
  • JustSteps
  • 2013年04月19日 19:43
  • 1694

CF_6D_LizardsAndBasements_2

D. Lizards and Basements 2 time limit per test 2 seconds memory limit per test 64 megabytes in...
  • baidu_29410909
  • baidu_29410909
  • 2016年03月30日 21:00
  • 386

Codeforces Beta Round #6 (Div. 2 Only) D. Lizards and Basements 2

dp[i][j][k]当前要打第i个怪,第i-1个怪的生命值为j,第i
  • u012287002
  • u012287002
  • 2014年08月26日 16:27
  • 401

D. Lizards and Basements 2 (DFS+最优性剪枝)

点击打开链接 http://codeforces.com/contest/6/problem/D D. Lizards and Basements 2 This is simpl...
  • liangzhaoyang1
  • liangzhaoyang1
  • 2017年04月09日 21:31
  • 357

Lizards and Basements 2 解题报告

Description This is simplified version of the problem used on the original contest. The origina...
  • cyendra
  • cyendra
  • 2013年01月30日 10:07
  • 995
收藏助手
不良信息举报
您举报文章:hdu 2732Leapin' Lizards
举报原因:
原因补充:

(最多只允许输入30个字)