Leapin' Lizards

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

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.
 思路:最大流,将每个点拆分成两个,一个为入流点一个为出流点,两点间建立流量为这个点处柱子的高度。
然后建立一个总输出点0,和总汇点,还有在两个距离不超过d的点之间建立流量为无穷的边,0和每个L的输入点建立流为1的边。最后跑下dinic。用所有的L-最大流即可。
  1 #include<stdio.h>
2 #include<algorithm>
3 #include<stdlib.h>
4 #include<iostream>
5 #include<string.h>
6 #include<vector>
7 #include<queue>
8 using namespace std;
9 struct node
10 {
11 int to;
12 int cap;
13 int rev;
14 };
15 char str[30][30];
16 char str2[30][30];
17 int id[30][30];
18 int level[100000];
19 vector<node>vec[100000];
20 const int N=1e8;
21 int iter[100000];
22 void add(int from,int to,int cap);
23 void bfs(int s);
24 int dfs(int s,int t,int f);
25 int max_flow(int s,int t);
26 int main(void)
27 {
28 int i,j,k;
29 scanf("%d",&k);
30 int s;
31 int p,q;
32 for(s=1; s<=k; s++)
33 {
34 scanf("%d %d ",&p,&q);
35 for(i=0; i<100000; i++)
36 vec[i].clear();
37 for(i=0; i<p; i++)
38 {
39 scanf("%s",str[i]);
40 }
41 for(i=0; i<p; i++)
42 {
43 scanf("%s",str2[i]);
44 }
45 int l=strlen(str[0]);
46 int ans=1;
47 for(i=0; i<p; i++)
48 {
49 for(j=0; j<l; j++)
50 {
51 id[i][j]=ans++;
52 }
53 }
54 ans-=1;
55 int x,y;
56 for(i=0; i<p; i++)
57 {
58 for(j=0; j<l; j++)
59 {
60 if(str[i][j]>'0')
61 add(id[i][j],id[i][j]+ans,str[i][j]-'0');
62 }
63 }
64 for(i=0; i<p; i++)
65 {
66 for(j=0; j<l; j++)
67 {
68 for(x=0; x<p; x++)
69 {
70 for(y=0; y<l; y++)
71 {
72 if(i!=x||j!=y)
73 {
74 if(abs(x-i)+abs(j-y)<=q)
75 {
76 add(id[i][j]+ans,id[x][y],N);
77 }
78 }
79 }
80 }
81 }
82 }
83 for(i=0; i<p; i++)
84 {
85 for(j=0; j<l; j++)
86 {
87 int cc=abs(i+1);
88 int dd=abs(p-i);
89 cc=min(cc,dd);
90 int kk=abs(j+1);
91 int vv=abs(l-j);
92 vv=min(kk,vv);
93 if((vv<=q||cc<=q))
94 {
95 add(id[i][j]+ans,2*ans+1,N);
96 }
97 }
98 }
99 int fuck=0;
100 for(i=0; i<p; i++)
101 {
102 for(j=0; j<l; j++)
103 {
104 if(str2[i][j]=='L')
105 {
106 add(0,id[i][j],1);
107 fuck++;
108 }
109 }
110 }
111 int sum=max_flow(0,2*ans+1);
112 printf("Case #%d: ",s);
113 if(fuck-sum==1)
114 printf("%d lizard was left behind.\n",fuck-sum);
115 else if(fuck-sum==0) printf("no lizard was left behind.\n");
116 else printf("%d lizards were left behind.\n",fuck-sum);
117 }
118 }
119 void add(int from,int to,int cap)
120 {
121 node nn;
122 nn.to=to;
123 nn.cap=cap;
124 nn.rev=vec[to].size();
125 vec[from].push_back(nn);
126 nn.to=from;
127 nn.cap=0;
128 nn.rev=vec[from].size()-1;
129 vec[to].push_back(nn);
130 }
131 void bfs(int s)
132 {
133 queue<int>que;
134 memset(level,-1,sizeof(level));
135 level[s]=0;
136 que.push(s);
137 while(!que.empty())
138 {
139 int v=que.front();
140 que.pop();
141 int i;
142 for(i=0; i<vec[v].size(); i++)
143 {
144 node e=vec[v][i];
145 if(level[e.to]==-1&&e.cap>0)
146 {
147 level[e.to]=level[v]+1;
148 que.push(e.to);
149 }
150 }
151 }
152 }
153 int dfs(int s,int t,int f)
154 {
155 if(s==t)
156 return f;
157 for(int &i=iter[s]; i<vec[s].size(); i++)
158 {
159 node &e=vec[s][i];
160 if(level[e.to]>level[s]&&e.cap>0)
161 {
162 int r=dfs(e.to,t,min(e.cap,f));
163 if(r>0)
164 {
165 e.cap-=r;
166 vec[e.to][e.rev].cap+=r;
167 return r;
168 }
169 }
170 }
171 return 0;
172 }
173 int max_flow(int s,int t)
174 {
175 int flow=0;
176 for(;;)
177 {
178 bfs(s);
179 if(level[t]<0)return flow;
180 memset(iter,0,sizeof(iter));
181 int f;
182 while((f=dfs(s,t,N))>0)
183 {
184 flow+=f;
185 }
186 }
187 }

Leapin' Lizards(hdu 2732)的更多相关文章

  1. POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流)

    POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流) Description Yo ...

  2. 【解题报告】 Leapin' Lizards HDU 2732 网络流

    [解题报告] Leapin' Lizards HDU 2732 网络流 题外话 在正式讲这个题目之前我想先说几件事 1. 如果大家要做网络流的题目,我在网上看到一个家伙,他那里列出了一堆网络流的题目, ...

  3. K - Leapin' Lizards - HDU 2732(最大流)

    题意:在一个迷宫里面有一些蜥蜴,这个迷宫有一些柱子组成的,并且这些柱子都有一个耐久值,每当一只蜥蜴跳过耐久值就会减一,当耐久值为0的时候这个柱子就不能使用了,每个蜥蜴都有一个最大跳跃值d,现在想知道有 ...

  4. Leapin' Lizards HDU - 2732 (恶心的建图。。)

    这道题其实不难...就是建图恶心了点....emm... 题意: 多源多汇 + 拆边 青蛙跳柱子, 每根柱子都有一定的承载能力, 青蛙跳上去之后柱子的承载能力就会减一,跳到边界就能活 跳不到就over ...

  5. Leapin' Lizards [HDU - 2732]【网络流最大流】

    题目链接 网络流直接最大流就是了,只是要拆点小心一个点的流超出了原本的正常范围才是. #include <iostream> #include <cstdio> #includ ...

  6. K - Leapin' Lizards HDU - 2732 网络流

    题目链接:https://vjudge.net/contest/299467#problem/K 这个题目从数据范围来看可以发现是网络流,怎么建图呢?这个其实不是特别难,主要是读题难. 这个建图就是把 ...

  7. HDU 2732 Leapin&#39; Lizards(拆点+最大流)

    HDU 2732 Leapin' Lizards 题目链接 题意:有一些蜥蜴在一个迷宫里面,有一个跳跃力表示能跳到多远的柱子,然后每根柱子最多被跳一定次数,求这些蜥蜴还有多少是不管怎样都逃不出来的. ...

  8. Leapin' Lizards(经典建图,最大流)

    Leapin' Lizards http://acm.hdu.edu.cn/showproblem.php?pid=2732 Time Limit: 2000/1000 MS (Java/Others ...

  9. HDU2732:Leapin' Lizards(最大流)

    Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

随机推荐

  1. day12 form组件

    day12 form组件 今日内容 form组件前戏 form组件基本定义 form组件数据校验功能 form组件渲染标签 form组件提示信息 数据校验进阶 form组件补充 form组件源码探索 ...

  2. Spark集群环境搭建——部署Spark集群

    在前面我们已经准备了三台服务器,并做好初始化,配置好jdk与免密登录等.并且已经安装好了hadoop集群. 如果还没有配置好的,参考我前面两篇博客: Spark集群环境搭建--服务器环境初始化:htt ...

  3. 零基础学习java------day1------计算机基础以及java的一些简单了解

    一. java的简单了解 Java是一门面向对象编程语言,不仅吸收了C++的各种优点,还摒弃了C++里难以理解的多继承.指针等概念,因此Java语言具有功能强大和简单易用两个特征.Java语言作为静态 ...

  4. 一条查询SQL查询语句的执行原理

    先熟悉一下浅而易懂SQL执行的流程图SQL查询过程七步曲 1.查询SQL发送请求 客户端将查询sql按照mysql通信协议传输到服务端.服务端接受到请求后,服务端单起一个线程执行sql 2.判断是否为 ...

  5. vue 第三方图标库

    "font-awesome": "^4.7.0", "dependencies": { "axios": "^ ...

  6. SpringMVC(1):SpringMVC入门

    一,MVC 概述 MVC:模型,视图,控制器,是一种软件设计规范,本质是将业务逻辑,数据,显示,分离的方式来编写代码:前后端分离 Model:数据模型,提供要展示的数据,一般我们都会把这两个分离开来. ...

  7. win10安装两台mysql-5.7.31实例

    1. 下载 mysql5.7.31 压缩包: (1)百度云下载: 链接:https://pan.baidu.com/s/1jgxfvIYzg8B8ahxU9pF6lg 提取码:fiid (2)官网下载 ...

  8. java关键字volatile内存语义详细分析

    volatile变量自身具有下列特性. 1.可见性.对一个volatile变量的读,总是能看到(任意线程)对这个volatile变量最后的写 入. · 2.原子性:对任意单个volatile变量的读/ ...

  9. Linux系统下安装tomcat

    一.前置条件 安装tomcat需要先安装jdk,所以没有安装jdk同学,详见参考文章 二.Linux上安装tomcat 1. 下载Apache tomcat tomcat官网下载地址 在左边,可以选择 ...

  10. C#中继承和多态

    1.继承的概念 继承是使用已存在的类的定义作为基础建立新类的技术,新类的定义可以增加新的数据或新的功能,也可以用已存在的类的功能. 为了提高软件模块的可复用性和可扩充性,以便提高软件的开发效率,我们总 ...