CF434D Nanami's Power Plant 最小割
因为连距离限制的边的细节调了贼久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 最小割的更多相关文章
- 【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]$ ...
- 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 ...
- CF434D Nanami's Power Plant
就是切糕那道题,首先对每个函数连一串,然后\(x_u\leq x_v+d\)这个条件就是\(u\)函数\(i\)取值连向\(v\)函数\(i-d\)取值边权为inf,然后答案就是最小割了. #incl ...
- CodeForces - 434D Nanami's Power Plant
Codeforces - 434D 题目大意: 给定一个长为n的序列,序列中的第i为上的值\(x_i\),序列第i位上的值\(x_i\in[l_i,r_i]\),价值为\(f_i(x_i)\),其中\ ...
- 【HDU 5855】Less Time, More profit(网络流、最小割、最大权闭合子图)
Less Time, More profit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- UVA 10480 Sabotage (网络流,最大流,最小割)
UVA 10480 Sabotage (网络流,最大流,最小割) Description The regime of a small but wealthy dictatorship has been ...
- bzoj1565【NOI2009】植物大战僵尸(最小割)
题目描述 Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻.该款游戏包含多 ...
- UVA10480:Sabotage(最小割+输出)
Sabotage 题目链接:https://vjudge.net/problem/UVA-10480 Description: The regime of a small but wealthy di ...
- 【二分 最小割】cf808F. Card Game
Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...
随机推荐
- Physical Plausible Shading
问所有人一个简单的问题,为什么我们做片子,CG生产的效果,就是不如论文中样图结果.难道是论文中用了某些神奇的黑科技?或者是依赖PS伪造的图?你当然不可能怀疑Cornell.Stanford这些一流机构 ...
- awesomium_v1.6.6_sdk 百度云下载地址
awesomium的官网已经关闭很久了,所以找不到正规的下载地址. 而csdn上面的又收费.所以这里提供一个不收费的百度云的下载地址给大家. 不足就是不是1.7版本,所以对于某些有特殊用途的满足不了了 ...
- 关于ARM CM3的启动文件分析
下面以ARM Cortex_M3裸核的启动代码为例,做一下简单的分析.首先,在启动文件中完成了三项工作: 1. 堆栈以及堆的初始化 2. 定位中断向量表 3. 调用Reset Handler. ...
- 口碑点餐相关问题FAQ
1.菜品上传中:出现重复错误或者违禁词 检查并修改商家中心本次上传中的重复菜品,或者删除口碑掌柜以及第三方平台已添加的重复菜品(重复菜品临时快捷办法:修改菜品名称) 2.手持pos 打开自动接单,无响 ...
- python 常见函数的用法
filter(function,ls) 函数包括两个参数,分别是function和list.该函数根据function参数返回的结果是否为真来过滤list参数中的项,最后返回一个新列表. 如: map ...
- 自动化测试基础篇--Selenium发送测试报告邮件
来自:https://www.cnblogs.com/sanzangTst/p/8377870.html 发邮件需要用到python两个模块,smtplib和email,这俩模块是python自带的, ...
- python第一百一十天--Django 5
#####################################中间件################################################ settings.py ...
- c/c++ 智能指针 shared_ptr 使用
智能指针 shared_ptr 使用 上一篇智能指针是啥玩意,介绍了什么是智能指针. 这一篇简单说说如何使用智能指针. 一,智能指针分3类:今天只唠唠shared_ptr shared_ptr uni ...
- C# -- 索引器、枚举类型
C# -- 索引器.枚举类型 索引器允许类或结构的实例就像数组一样进行索引. 无需显式指定类型或实例成员,即可设置或检索索引值. 索引器类似于属性,不同之处在于它们的访问器需要使用参数. 1. 索引器 ...
- LeetCode算法题-Move Zeroes(Java实现-三种解法)
这是悦乐书的第201次更新,第211篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第67题(顺位题号是283).给定一个数组nums,写一个函数将所有0移动到它的末尾,同 ...