gym 101194 J Mr.Panda and TubeMaster (费用流)

题意

给定一张n*m的方格,每个方格放可以放4种类型的直角管道,并给出几个重要点,保证每个重要点都存在管道,且管道围成一个环。现给出每个管道连接两个方格能赚的钱,输出最多赚多少钱。若不存在方案输出impossible。

题解

可以发现每个方格都存在上下流向和左右流向的管道,且方格之间相互连接的管道方向是不同的,因此想到可以将方格黑白染色,白色代表该方格中的管道只左右流,黑色代表该方格中的管道只上下流,之后我们再把点拆成出点和入点,就可以将相邻方格连接起来了,之后我们设定流量上线为n*m,即每个方格都存在流量,对于那些非重要点,我们将其出点连向入点,代表该方格无管道,之后跑个最大费用最大流即可

代码

/**
 *     author:     TelmaZzzz
 *     create:     2019-10-06-17.59.54
**/
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
void _R(int &x) {
    scanf("%d", &x); }
void _R(ll &x) {
    scanf("%lld", &x); }
void _R(db &x) {
    scanf("%lf", &x); }
void _R(char &x) {
    scanf(" %c", &x); }
void _R(char *x) {
    scanf("%s", x); }
void R() {
   }
template<class T, class... U> void R(T &head, U &... tail) {
    _R(head); R(tail...); }
void _W(const int &x) {
    printf("%d", x); }
void _W(const ll &x) {
    printf("%lld", x); }
void _W(const db &x) {
    printf("%.16f", x); }
void _W(const char &x) {
    putchar(x); }
void _W(const char *x) {
    printf("%s", x); }
template<class T> void _W(const vector<T> &x) {
    for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值