这道题其实不难。。。就是建图恶心了点。。。。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 (恶心的建图。。)的更多相关文章

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

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

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

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

  3. hdu 2732 Leapin' Lizards 最大流 拆点 建图

    题目链接 题意 给定一张网格,格子中有些地方有柱子,有些柱子上面有蜥蜴. 每个柱子只能承受有限只蜥蜴从上面经过.每只蜥蜴每次能走到相距曼哈顿距离\(\leq k\)的格子中去. 问有多少只蜥蜴能走出网 ...

  4. hdu 2732 Leapin' Lizards (最大流 拆点建图)

    Problem Description Your platoon of wandering lizards has entered a strange room in the labyrinth yo ...

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

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

  6. Leapin' Lizards(hdu 2732)

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

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

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

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

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

  9. 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轮的策略不一 ...

随机推荐

  1. TerraGate SFS 4.5 版本 发布矢量数据使用的Cache数据如何再返回成shapefile文件

    TerraGate SFS 4.5 版本 发布矢量数据使用的Cache数据如何再返回成shapefile文件? 两年前帮一个朋友解决过这个问题: 如果原来用4.5版本的时候,在网络环境下,为了提升调用 ...

  2. SkylineGlobe 从v6.1到v6.5 二次开发方面的变化参考

       2.1关于 TerraExplorer v6.5 API 除了一些新的功能,API v6.5不同于API v6.1的最大改进是其对象ID系统.虽然在以前版本的API中,有两个ID系统,一个用于对 ...

  3. 1-微信小程序开发(安装软件和运行第一个微信小程序)

    https://developers.weixin.qq.com/miniprogram/dev/ 我的 打开 上传成功后

  4. ES6 Promise 异步操作

    最近越来越喜欢与大家进行资源分享了,并且及时的同步到自己的园子内,为什么呢? 一.小插曲(气氛搞起) 在上个月末,由于领导的高度重视(haha,这个高度是有多高呢,185就好了),走进了公司骨干员工的 ...

  5. Luogu P1966 火柴排队

    这还是一道比较简单的题目,稍微想一下就可以解决.终于有NOIP难度的题目了 首先我们看那个∑(ai-bi)^2的式子,发现这个的最小值就是排序不等式 所以我们只需要改变第一组火柴的顺序,使它和第二组火 ...

  6. python棋类游戏编写入门

    刚接触棋类游戏程序编写的朋友,往往比较迷惑,不知从何下手. 本文总结了棋类游戏的主程序流程.计算机走子策略.打分方式(以井字棋.黑白棋.五子棋为例),未使用minimax算法,比较简单,适合刚接触的朋 ...

  7. Scala学习(七)练习

    控制结构和函数 1. 编写示例程序,展示为什么 package com.horstmann.impatient 不同于 package com package horstmann package im ...

  8. XenServer虚拟化环境安装记录

    Xenserver,思杰基于Xen的虚拟化服务器.Citrix XenServer是一种全面而易于管理的服务器虚拟化平台,基于强大的 Xen Hypervisor 程序之上.XenServer 是为了 ...

  9. Docker容器学习梳理 - 容器登陆方法梳理(attach、exec、nsenter)

    对于运行在后台的Docker容器,我们运维人员时常是有登陆进去的需求.登陆Docker容器的方式:1)使用ssh登陆容器.这种方法需要在容器中启动sshd,存在开销和攻击面增大的问题.同时也违反了Do ...

  10. 6大爱上react 的理由

    本文翻译自:https://blog.syncano.io/reactjs-reasons-why-part-1/ 书写javascript 更加简单 (⚠️js 中混用html 也一直是外界所诟病的 ...