Codeforces Round #248 (Div. 1) D - Nanami's Power Plant 最小割
思路:类似与bzoj切糕那道题的模型。。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ;
const double eps = 1e-;
const int MAX = 2e5; int head[N], level[N], tot, S, T;
int n, m, a[N], b[N], c[N], L[N], R[N];
struct node {
int to, w, nx;
} edge[]; void add(int u, int v, int w) {
edge[tot].to = v;
edge[tot].w = w;
edge[tot].nx = head[u];
head[u] = tot++; edge[tot].to = u;
edge[tot].w = ;
edge[tot].nx = head[v];
head[v] = tot++;
} bool bfs() {
memset(level, , sizeof(level));
queue<int> que; level[S] = ; que.push(S);
while(!que.empty()) {
int u = que.front(); que.pop();
if(u == T) return true;
for(int i = head[u]; ~i; i = edge[i].nx) {
int v = edge[i].to, w = edge[i].w;
if(level[v] || w <= ) continue;
level[v] = level[u] + ;
que.push(v);
}
}
return false;
} int dfs(int u, int p) {
if(u == T) return p;
int ret = ;
for(int i = head[u]; ~i; i = edge[i].nx) {
int v = edge[i].to, w = edge[i].w;
if(level[v] != level[u] + || w <= ) continue;
int f = dfs(v, min(w, p - ret));
ret += f;
edge[i].w -= f;
edge[i ^ ].w += f;
if(ret == p) break;
}
if(!ret) level[u] = ;
return ret;
} int Dinic() {
int ans = ;
while(bfs()) ans += dfs(S, inf);
return ans;
}
void init() {
memset(head, -, sizeof(head));
tot = ;
} inline int ID(int x, int y) {
return x*+y+;
}
inline int getVal(int who, int x) {
return a[who]*x*x + b[who]*x + c[who];
} int main() {
init();
S = , T = ;
cin >> n >> m;
for(int i = ; i <= n; i++) cin >> a[i] >> b[i] >> c[i];
for(int i = ; i <= n; i++) {
cin >> L[i] >> R[i];
add(S, ID(i, L[i]-), inf);
for(int j = L[i]; j <= R[i]; j++)
add(ID(i, j-), ID(i, j), MAX-getVal(i, j));
add(ID(i, R[i]), T, inf);
}
while(m--) {
int u, v, d;
cin >> u >> v >> d;
for(int j = L[u]; j <= R[u]; j++)
if(j-d>=L[v] && j-d-<=R[v])
add(ID(u, j-), ID(v, j-d-), inf);
}
printf("%d\n", n*MAX-Dinic());
return ;
} /*
*/
Codeforces Round #248 (Div. 1) D - 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) B. Nanami's Digital Board 暴力 前缀和
B. Nanami's Digital Board 题目连接: http://www.codeforces.com/contest/434/problem/B Description Nanami i ...
- CF434D Nanami's Power Plant 最小割
传送门 因为连距离限制的边的细节调了贼久QAQ 这个题和HNOI2013 切糕性质相同,都是有距离限制的最小割问题 对于每一个函数,用一条链记录变量\(x\)在不同取值下这个函数的贡献.对于一个\(x ...
- Codeforces Round #248 (Div. 1)——Nanami's Digital Board
题目连接 题意: 给n*m的0/1矩阵,q次操作,每次有两种:1)将x,y位置值翻转 2)计算以(x,y)为边界的矩形的面积最大值 (1 ≤ n, m, q ≤ 1000) 分析: 考虑以(x,y)为 ...
- Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)
比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...
- Codeforces Round #248 (Div. 2) C. Ryouko's Memory Note
题目链接:http://codeforces.com/contest/433/problem/C 思路:可以想到,要把某一个数字变成他的相邻中的数字的其中一个,这样总和才会减少,于是我们可以把每个数的 ...
- Codeforces Round #248 (Div. 2)C 题
题目:http://codeforces.com/contest/433/problem/C 没想到做法就各种纠结, 今天做的都快疯掉了, 太弱了, 等题解一出,就各种恍然大悟 不应该不应该 正文: ...
- Codeforces Round #248 (Div. 1) A. Ryouko's Memory Note 水题
A. Ryouko's Memory Note 题目连接: http://www.codeforces.com/contest/434/problem/A Description Ryouko is ...
- Codeforces Round #248 (Div. 2) B称号 【数据结构:树状数组】
主题链接:http://codeforces.com/contest/433/problem/B 题目大意:给n(1 ≤ n ≤ 105)个数据(1 ≤ vi ≤ 109),当中有m(1 ≤ m ≤ ...
随机推荐
- python---web微信开发
一:轮询,长轮询,WebSocket了解 轮询: 在前端,设置时间内,一直向后端发送请求.例如:使用setInterval方法设置定时器,一秒向后端发送一次请求,去主动获取数据,进行更新由于前端一直请 ...
- git 分支管理——多人协作
git 分支管理--多人协作 一般一个项目有一个master主分支,还有一个develop开发分支.主要是在develop分支上协作开发,然后merge合并到master主分支上. 当从远程仓库克隆时 ...
- NOIP2016 组合数问题
https://www.luogu.org/problem/show?pid=2822 题目描述 组合数表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三个物品中选择两个物品可以 ...
- [洛谷P4491] [HAOI2018]染色
洛谷题目链接:[HAOI2018]染色 题目背景 HAOI2018 Round2 第二题 题目描述 为了报答小 C 的苹果, 小 G 打算送给热爱美术的小 C 一块画布, 这块画布可 以抽象为一个长度 ...
- 细说 struct和typedef struct
细说 struct和typedef struct 参考原文:http://www.cnblogs.com/qyaizs/articles/2039101.html,有些小改动~ 1 首先://注意在C ...
- 分享自己新做的vim colorscheme
把下面的内容保存成darkslategrey.vim,放入~/.vim/colors目录即可. " Vim color file " Maintainer: jiqing() &q ...
- 【清华集训 2017】小Y的地铁 [模拟退火]
小Y的地铁 Time Limit: 50 Sec Memory Limit: 256 MB Description Input Output 对于每组输入数据,输出一行一个整数,表示除掉这 n 个换 ...
- 20155321 2016-2017-2 《Java程序设计》第六周学习总结
20155321 2016-2017-2 <Java程序设计>第六周学习总结 教材学习内容总结 第十章 IO 流 IO 流用来处理设备之间的数据传输 Java对数据的操作是通过流的方式 J ...
- select 函数小结 -- 转自百度知道
http://zhidao.baidu.com/link?url=UVTXeK4ncKmnwatGUW2deMFylNYBuur-zHmK3w53NXNRpgPbhld2WdkMD766nKl_6Hj ...
- HAOI 2005 路由选择问题 (最短路+次短路)
问题描述 X城有一个含有N个节点的通信网络,在通信中,我们往往关心信息从一个节点I传输到节点J的最短路径.遗憾的是,由于种种原因,线路中总有一些节点会出故障,因此在传输中要避开故障节点. 任务一:在己 ...