传送门


因为连距离限制的边的细节调了贼久QAQ

这个题和HNOI2013 切糕性质相同,都是有距离限制的最小割问题

对于每一个函数,用一条链记录变量\(x\)在不同取值下这个函数的贡献。对于一个\(x_u \leq x_v + d\)的限制,用一条\(INF\)的边连接链上对应的两个点来限制这个条件。

注意一些细节的地方:

①注意每一个限制中每一个点对应另一条链的哪一个点,一定要想清楚;

②如果\(c<0\),链上还会存在一些点不可能被割掉,还要连\(S\)和\(T\)相关的边限制这样的割。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<vector>
#include<cmath>
#include<random>
#include<cassert>
#define int long long
#define inf 1e10
#define INF 1e13
//This code is written by Itst
using namespace std;

const int MAXN = 1e5 + 7 , MAXM = 1e6 + 7;
struct Edge{
    int end , upEd , f , c;
}Ed[MAXM];
int head[MAXN] , a[51] , b[51] , c[51] , l[51] , r[51] , ind[51][207];
int N , M , S , T , cntEd = 1;
queue < int > q;

inline void addEd(int a , int b , int c , int d = 0){
    Ed[++cntEd].end = b;
    Ed[cntEd].upEd = head[a];
    Ed[cntEd].f = c;
    Ed[cntEd].c = d;
    head[a] = cntEd;
}

inline void addE(int a , int b , int c , int d = 0 , bool f = 0){
    addEd(a , b , c , d); addEd(b , a , c * f , -d);
}

int cur[MAXN] , dep[MAXN];

inline bool bfs(){
    while(!q.empty())
        q.pop();
    q.push(S);
    memset(dep , 0 , sizeof(dep));
    dep[S] = 1;
    while(!q.empty()){
        int t = q.front();
        q.pop();
        for(int i = head[t] ; i ; i = Ed[i].upEd)
            if(Ed[i].f && !dep[Ed[i].end]){
                dep[Ed[i].end] = dep[t] + 1;
                if(Ed[i].end == T){
                    memcpy(cur , head , sizeof(head));
                    return 1;
                }
                q.push(Ed[i].end);
            }
    }
    return 0;
}

inline int dfs(int x , int mF){
    if(x == T)
        return mF;
    int sum = 0;
    for(int &i = cur[x] ; i ; i = Ed[i].upEd)
        if(Ed[i].f && dep[Ed[i].end] == dep[x] + 1){
            int t = dfs(Ed[i].end , min(mF - sum , Ed[i].f));
            if(t){
                Ed[i].f -= t;
                Ed[i ^ 1].f += t;
                sum += t;
                if(sum == mF)
                    break;
            }
        }
    return sum;
}

int Dinic(){
    int ans = 0;
    while(bfs())
        ans += dfs(S , INF);
    return ans;
}

inline int calc(int tp , int x){
    return a[tp] * x * x + b[tp] * x + c[tp];
}

signed main(){
#ifndef ONLINE_JUDGE
    freopen("in" , "r" , stdin);
    //freopen("out" , "w" , stdout);
#endif
    ios::sync_with_stdio(0);
    cin >> N >> M;
    for(int i = 1 ; i <= N ; ++i) cin >> a[i] >> b[i] >> c[i];
    T = 1e5;
    int cnt = 0;
    for(int i = 1 ; i <= N ; ++i){
        cin >> l[i] >> r[i];
        for(int j = 0 ; j <= 200 ; ++j) ind[i][j] = ++cnt;
        addE(S , ind[i][0] , l[i] == -100 ? inf - calc(i , -100) : INF);
        addE(ind[i][200] , T , INF);
        for(int j = 1 ; j <= 200 ; ++j)
            addE(ind[i][j - 1] , ind[i][j] , j - 100 >= l[i] && j - 100 <= r[i] ? inf - calc(i , j - 100) : INF);
    }
    while(M--){
        int a , b , c;
        cin >> a >> b >> c;
        for(int i = max(0ll , c) ; i <= min(200ll , 200 + c) ; ++i)
            addE(ind[a][i] , ind[b][i - c] , INF);
        if(c < 0){
            addE(S , ind[b][-c - 1] , INF);
            addE(ind[a][200 + c] , T , INF);
        }
    }
    cout << (int)(N * inf - Dinic());
    return 0;
}

CF434D Nanami's Power Plant 最小割的更多相关文章

  1. 【CF434D】Nanami's Power Plant 最小割

    [CF434D]Nanami's Power Plant 题意:有n个二次函数$y=a_ix^2+b_ix+c_i$($a_i,b_i,c_i$是整数),第i个函数要求x的取值在$[l_i,r_i]$ ...

  2. Codeforces Round #248 (Div. 1) D - Nanami's Power Plant 最小割

    D - Nanami's Power Plant 思路:类似与bzoj切糕那道题的模型.. #include<bits/stdc++.h> #define LL long long #de ...

  3. CF434D Nanami's Power Plant

    就是切糕那道题,首先对每个函数连一串,然后\(x_u\leq x_v+d\)这个条件就是\(u\)函数\(i\)取值连向\(v\)函数\(i-d\)取值边权为inf,然后答案就是最小割了. #incl ...

  4. CodeForces - 434D Nanami's Power Plant

    Codeforces - 434D 题目大意: 给定一个长为n的序列,序列中的第i为上的值\(x_i\),序列第i位上的值\(x_i\in[l_i,r_i]\),价值为\(f_i(x_i)\),其中\ ...

  5. 【HDU 5855】Less Time, More profit(网络流、最小割、最大权闭合子图)

    Less Time, More profit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  6. UVA 10480 Sabotage (网络流,最大流,最小割)

    UVA 10480 Sabotage (网络流,最大流,最小割) Description The regime of a small but wealthy dictatorship has been ...

  7. bzoj1565【NOI2009】植物大战僵尸(最小割)

    题目描述 Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻.该款游戏包含多 ...

  8. UVA10480:Sabotage(最小割+输出)

    Sabotage 题目链接:https://vjudge.net/problem/UVA-10480 Description: The regime of a small but wealthy di ...

  9. 【二分 最小割】cf808F. Card Game

    Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...

随机推荐

  1. 33.Odoo产品分析 (四) – 工具板块(4) – 问题追踪及群发邮件营销(1)

    查看Odoo产品分析系列--目录 问题追踪 该应用程序允许您管理项目中可能遇到的问题,如系统中的bug.客户投诉或物料故障.  该模块安装后没有菜单显示,而是作为后台管理,接收一些问题报告. 群发邮件 ...

  2. 随笔:Oracle实验课(软件系统开发综合实践)B/S结构;java——图书管理系统

    以上是我需要注意的要求 -------------------------------此处为放假分割线-1-20----------------------------------- 初步完成了整个程 ...

  3. win7文件搜索技巧

    重要说明   (1)搜索的字符串是大小写不敏感的 (2)字符串带双引号与不带双引号是有区别的 如:hello,搜索包含hello单词开头的文件或目录,名为“aa_HELLOcc...”.“cc-Hel ...

  4. CentOS7中启动Tomcat后,8080端口不能被外部访问的解决办法。

    运行:/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

  5. web前端(3)—— html标签及web页面结构

    本节内容简单介绍下html都有哪些标签 还是百度首页,查看源代码看看: 我把源代码复制下来另存为html文件里: 注意:网页文件的后缀都是html或者htm 我这用的pycharm编辑器(Python ...

  6. C# -- 交错数组的使用

    C# -- 交错数组的使用 交错数组是元素为数组的数组.交错数组元素的维度和大小可以不同.交错数组有时称为“数组的数组”. 1. 举例一:子数组是长度相同的一维数组 static void Main( ...

  7. FCM算法的matlab程序(初步)

    FCM算法的matlab程序 在https://www.cnblogs.com/kailugaji/p/9648430.html文章中已经介绍了FCM算法,现在用matlab程序实现它. 作者:凯鲁嘎 ...

  8. java使用elasticsearch实现集群管理

    本篇博客主要是查看集群中的相关信息,具体请看代码和注释 @Test public void test45() throws UnknownHostException{ //1.指定es集群 clust ...

  9. Spring的AOP基于AspectJ的注解方式开发3

    上上偏博客介绍了@Aspect,@Before 上篇博客介绍了spring的AOP开发的注解通知类型:@Before,@AfterThrowing,@After,@AfterReturning,@Ar ...

  10. 【PS技巧】常用概念和功能操作

    常用概念 1.画布大小与图像大小 画布大小是图像背景的大小,即画纸.图像大小是当前编辑的图层的所有对象大小,即画纸上的画. 常用功能操作 1.打开和新建功能 打开图片:Ctrl+O或双击工作区 图片垂 ...