【HDU2732】【点限制】【最大流】
来源:互联网 发布:整人软件 编辑:程序博客网 时间:2024/05/21 17:42
Leapin' Lizards
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1752 Accepted Submission(s): 717
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.
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.
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
43 1111111111111LLLLLLLLLLLL3 2000000111000000......LLL......3 1000000111000000......LLL......5 20000000002000000003211000200000000000000..................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
Mid-Central USA 2005
int T;int n,d;const int maxn = 35;char str[maxn];int mat[maxn][maxn];int planum;int sum;int m;Max_Flow<int> MF;int main(){ scanf("%d",&T);int iCase = 0;while(T --){iCase ++;scanf("%d%d",&n,&d);memset(mat,0,sizeof(mat));MF.Init(1600,1,2);planum = 0;sum = 0;for(int i=0;i<n;i++){scanf("%s",str);int len = strlen(str);m = strlen(str);for(int j=0;j<len;j++){if(str[j] > '0'){mat[i][j] = ++planum;MF.Add_edge(planum*2-1,planum*2,str[j]-'0');}}}for(int i=0;i<n;i++){scanf("%s",str);int len = strlen(str);for(int j=0;j<len;j++){if(str[j] == 'L'){sum ++;MF.Add_edge(0,2*mat[i][j]-1,1);}}}for(int i=0;i<n;i++){for(int j=0;j<m;j++){if(mat[i][j]){for(int x=-d;x<=d;x++){for(int y=abs(x)-d;y<=d-abs(x);y++){int newi = i + x;int newj = j + y;if(newi < 0 || newi >= n || newj < 0 || newj >= m) continue;if(mat[newi][newj] == 0) continue;if(newi == i && newj == j) continue;MF.Add_edge(2*mat[i][j],2*mat[newi][newj]-1,0x3f3f3f3f);}}if(i < d || j < d || n - i <= d || m - j <= d){MF.Add_edge(2*mat[i][j],2*planum+1,0x3f3f3f3f);}}}}MF.ChangeNST(2*planum+2,0,2*planum+1);int ret = MF.Dinic();int ans = sum - ret; if(ans==0)printf("Case #%d: no lizard was left behind.\n",iCase); else if(ans==1)printf("Case #%d: 1 lizard was left behind.\n",iCase); else printf("Case #%d: %d lizards were left behind.\n",iCase,ans);} return 0;}
0 0
- 【HDU2732】【点限制】【最大流】
- hdu2732最大流
- hdu2732 最大流~
- HDU2732 最大流..
- HDU2732 Leapin' Lizards(最大流)
- hdu2732 Leapin' Lizards(较难) [最大流]
- 网络流 HDU2732 && PKU 2711 最大流 SAP
- hdu2732,网络流
- 【网络流】hdu2732 Leapin' Lizards
- 网络流。。。。经典模型。。。HDU2732 && PKU 2711
- poj 3498 March of the Penguins 点流量有限制的最大流
- poj 3422 有流量限制的最小费用流 反用求最大 + 拆点
- 最大流最大点权独立集
- POJ2396-带上下限制的最大流
- SGU242 最大流 容量限制为2
- 【POJ3281】【最大流】【加边限制流量】
- POJ3498 拆点最大流
- 【最大流 && 点限流】HDU
- 一维数组(Xcode)
- 【Java多线程】-线程中断
- jquery(2)
- Android进阶(十八)AndroidAPP开发问题汇总(二)
- iOS 手机相册英文字母的设定
- 【HDU2732】【点限制】【最大流】
- XTU 1236 Fraction 二分
- 某MIT计算机学生谈学数学
- LINUX信号- sigaction 函数-10.14
- Delphi 7下使用Log4Delphi 0.8日志组件
- call by value 和call by reference
- 第一章 Xen与kvm
- hibnate 测试注意点
- getContentLength=-1