Leapin' Lizards HDU - 2732 (恶心的建图。。)
这道题其实不难。。。就是建图恶心了点。。。。emm。。。
题意:
多源多汇 + 拆边
青蛙跳柱子, 每根柱子都有一定的承载能力, 青蛙跳上去之后柱子的承载能力就会减一,跳到边界就能活 跳不到就over了,青蛙有一个最大的跳跃距离dis, 把每根柱子拆成两个点, 中间连一条边,为柱子的承载能力, 每个青蛙的初始位置都为一个源 边界为汇 , 建立超级源s和超级汇t , s连接所有青蛙的起点,权值为1, 边界和 距离青蛙起点小于dis的点连接t, 权值为INF, 并且建立u->u' u'->v 的边
看完题想建图的时候觉得暴力建图肯定会超时,然后实在想不出什么好的建图方法, 然后暴力建图, emm。。。竟然没超时。。。 还有注意output的英语语法!!!
Dinic + 弧优化:。。。。现在只会写这个了。。。
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define maxn 1000000
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int INF = 0x3f3f3f3f;
int head[maxn], d[maxn], cur[maxn];
int n, m, s, t, dis;
int cnt = ;
struct node{
int u, v, c, next;
}Node[maxn*]; void add_(int u, int v, int c)
{
Node[cnt].u = u;
Node[cnt].v = v;
Node[cnt].c = c;
Node[cnt].next = head[u];
head[u] = cnt++;
} void add(int u, int v, int c)
{
add_(u,v,c);
add_(v,u,);
} bool bfs()
{
queue<int> Q;
mem(d,);
d[s] = ;
Q.push(s);
while(!Q.empty())
{
int u = Q.front(); Q.pop();
for(int i=head[u]; i!=-; i=Node[i].next)
{
node e = Node[i];
if(!d[e.v] && e.c > )
{
d[e.v] = d[e.u] + ;
Q.push(e.v);
if(e.v == t) return ;
}
}
}
return d[t] != ;
} int dfs(int u, int cap)
{
if(u == t || cap == )
return cap;
int ret = ;
for(int &i=cur[u]; i!=-; i=Node[i].next)
{
node e = Node[i];
if(d[e.v] == d[u] + && e.c > )
{
int V = dfs(e.v, min(cap, e.c));
Node[i].c -= V;
Node[i^].c += V;
ret += V;
cap -= V;
if(cap == ) break;
}
}
return ret;
} int Dinic()
{
int ans = ;
while(bfs())
{
memcpy(cur, head, sizeof(head));
ans += dfs(s, INF);
}
return ans;
} int main()
{
char str[][], map[maxn];
int bz[][];
int T, kase = ;
scanf("%d",&T);
while(T--)
{
cnt = ;
int ret = ;
mem(bz,);
mem(head,-);
int ans = ;
scanf("%d%d",&n,&dis);
for(int i=; i<n; i++)
scanf("%s",&str[i]);
for(int i=; i<n; i++)
{
int len = strlen(str[i]);
if( i == ) s = , t = * len * n + ;
for(int j=; j<len; j++)
{
ans++;
int temp = str[i][j] - '';
if(temp != )
{
add(ans, n*len + ans, temp);
if(i-dis < || i+dis >=n || j-dis < || j+dis >= len){
add(n*len+ans, t, INF);
}
for(int k=-dis; k<=dis; k++)
{
for(int g=-dis; g<=dis; g++)
{
int nx = i + k;
int ny = j + g;
if(nx == i && ny == j) continue;
if(nx < || nx >= n || ny < || ny >= len || str[i][j] == '' || abs(i-nx) + abs(j-ny) > dis)
continue;
add(n*len+ans, nx*len+ny+, INF);
// add(n*len+bz[nx][ny], ans, INF);
}
}
}
}
}
for(int i=; i<n; i++)
{
scanf("%s",map);
for(int j=; j<strlen(map); j++)
{
if(map[j] == 'L')
{
ret++;
add(s, i*strlen(map)+j+, );
}
}
}
// for(int i=0; i<cnt; i++)
// cout<< Node[i].u << " " << Node[i].v << " " <<Node[i].c<<endl; int op = ret - Dinic();
// for(int i=0; i<cnt; i++)
// cout<< Node[i].u << " " << Node[i].v << " " <<Node[i].c<<endl; if(op > )
printf("Case #%d: %d lizards were left behind.\n",++kase,op);
else if(op == )
printf("Case #%d: no lizard was left behind.\n",++kase);
else if(op == )
printf("Case #%d: 1 lizard was left behind.\n",++kase); }
return ;
}
Leapin' Lizards HDU - 2732 (恶心的建图。。)的更多相关文章
- 【解题报告】 Leapin' Lizards HDU 2732 网络流
[解题报告] 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 ...
- hdu 2732 Leapin' Lizards 最大流 拆点 建图
题目链接 题意 给定一张网格,格子中有些地方有柱子,有些柱子上面有蜥蜴. 每个柱子只能承受有限只蜥蜴从上面经过.每只蜥蜴每次能走到相距曼哈顿距离\(\leq k\)的格子中去. 问有多少只蜥蜴能走出网 ...
- hdu 2732 Leapin' Lizards (最大流 拆点建图)
Problem Description Your platoon of wandering lizards has entered a strange room in the labyrinth yo ...
- K - Leapin' Lizards HDU - 2732 网络流
题目链接:https://vjudge.net/contest/299467#problem/K 这个题目从数据范围来看可以发现是网络流,怎么建图呢?这个其实不是特别难,主要是读题难. 这个建图就是把 ...
- Leapin' Lizards(hdu 2732)
Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- K - Leapin' Lizards - HDU 2732(最大流)
题意:在一个迷宫里面有一些蜥蜴,这个迷宫有一些柱子组成的,并且这些柱子都有一个耐久值,每当一只蜥蜴跳过耐久值就会减一,当耐久值为0的时候这个柱子就不能使用了,每个蜥蜴都有一个最大跳跃值d,现在想知道有 ...
- Leapin' Lizards [HDU - 2732]【网络流最大流】
题目链接 网络流直接最大流就是了,只是要拆点小心一个点的流超出了原本的正常范围才是. #include <iostream> #include <cstdio> #includ ...
- Eliminate the Conflict HDU - 4115(2-sat 建图 hhh)
题意: 石头剪刀布 分别为1.2.3,有n轮,给出了小A这n轮出什么,然后m行,每行三个数a b k,如果k为0 表示小B必须在第a轮和第b轮的策略一样,如果k为1 表示小B在第a轮和第b轮的策略不一 ...
随机推荐
- ftrace利器之trace-cmd和kernelshark
关键词:ftrace.trace-cmd.kernelshark. trace-cmd是设置读取ftrace的命令行工具,kernelshark既可以记录数据,也可以图形化分析结果. trace-cm ...
- 解决System.Runtime.CompilerServices.ExtensionAttribute..ctor 与 ‘ExtensionAttribute’ is ambiguous in the namespace ‘System.Runtime.CompilerServices’ 问题
从VSS上获取以前的老项目,编译时报System.Runtime.CompilerServices.ExtensionAttribute..ctor 网上写的“删除 Newtonsoft.Json.N ...
- sqlserver 发送http请求
sp_configure 'show advanced options', 1; GO RECONFIGURE; GO sp_configure 'Ole Automation Procedures' ...
- 在线图标制作,格式转换 ICON
在线图标制作,格式转换 https://www.easyicon.net/covert/
- [Spark][Python]sortByKey 例子
[Spark][Python]sortByKey 例子: [training@localhost ~]$ hdfs dfs -cat test02.txt00002 sku01000001 sku93 ...
- 记一次在.NET成长之路上的下午茶
在2017年2月25日我和李海国有幸与阳铭.朱永光两位大哥喝了一次下午茶.熟悉ABP框架的朋友呢知道阳铭远在上海,所以个人很是珍惜这次机会.朱永光大哥是微软MVP,之前是启路科技的CTO,目前在微软. ...
- 函数:this & return、break、continue、exit()
this this:的指向在函数定义的时候是确定不了的,只有函数执行的时候才能确定this到底指向谁,实际上this的最终指向的是那个调用它的对象在调用的时候才能决定,谁调用的就指向谁. 情景1:指向 ...
- linux第四次读书笔记
第四章:进程调度 一.多任务 1.非抢占式多任务 进程会一直执行直到自己主动停止运行(这一步骤称为让步) 2.抢占式多任务 Linux/Unix使用的是抢占式的方式:强制的挂起进程的动作就叫做抢占.进 ...
- Software Engineering homework2
现在市面上有诸多软件,选取一类软件,请分析: Q1:此类软件是什么时候出现的,这些软件是怎么说服你(陌生人)成为它们的用户的?他们的目标都是盈利的么?他们的目标都是赚取用户的现金的么?还是别的? A1 ...
- 第三个Sprint冲刺第5天
成员:罗凯旋.罗林杰.吴伟锋.黎文衷 各成员努力完成最后冲刺