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 最小割的更多相关文章

  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) B. Nanami's Digital Board 暴力 前缀和

    B. Nanami's Digital Board 题目连接: http://www.codeforces.com/contest/434/problem/B Description Nanami i ...

  3. CF434D Nanami's Power Plant 最小割

    传送门 因为连距离限制的边的细节调了贼久QAQ 这个题和HNOI2013 切糕性质相同,都是有距离限制的最小割问题 对于每一个函数,用一条链记录变量\(x\)在不同取值下这个函数的贡献.对于一个\(x ...

  4. Codeforces Round #248 (Div. 1)——Nanami&#39;s Digital Board

    题目连接 题意: 给n*m的0/1矩阵,q次操作,每次有两种:1)将x,y位置值翻转 2)计算以(x,y)为边界的矩形的面积最大值 (1 ≤ n, m, q ≤ 1000) 分析: 考虑以(x,y)为 ...

  5. Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)

    比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...

  6. Codeforces Round #248 (Div. 2) C. Ryouko's Memory Note

    题目链接:http://codeforces.com/contest/433/problem/C 思路:可以想到,要把某一个数字变成他的相邻中的数字的其中一个,这样总和才会减少,于是我们可以把每个数的 ...

  7. Codeforces Round #248 (Div. 2)C 题

    题目:http://codeforces.com/contest/433/problem/C 没想到做法就各种纠结, 今天做的都快疯掉了, 太弱了, 等题解一出,就各种恍然大悟 不应该不应该 正文: ...

  8. 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 ...

  9. Codeforces Round #248 (Div. 2) B称号 【数据结构:树状数组】

    主题链接:http://codeforces.com/contest/433/problem/B 题目大意:给n(1 ≤ n ≤ 105)个数据(1 ≤ vi ≤ 109),当中有m(1 ≤ m ≤  ...

随机推荐

  1. 获取异常信息e.printStackTrace()的内容

    获取异常信息e.printStackTrace()的内容 最近做项目的时候需要记录操作的日志,但是记录异常信息的是发现使用e.getMessage()根本无法满足需要,并且e.getMessage() ...

  2. python安装包提示error: option --single-version-externally-managed not recognized

    pip install mysql-connector-python-rf==2.2.2 安装包的时候提示错误信息:error:option--single-version-externally-ma ...

  3. python学习笔记3-函数的递归

    递归就是指自己函数的自我调用 #递归 #自己调用自己,函数的循环 def test1(): num = int(input('please enter a number:')) if num%2==0 ...

  4. noip2012 P1081 开车旅行

    小 A 和小 B 决定利用假期外出旅行,他们将想去的城市从 1 到 N 编号,且编号较小的城市在编号较大的城市的西边,已知各个城市的海拔高度互不相同,记城市 i 的海拔高度为Hi,城市 i 和城市 j ...

  5. Caffe的loss layer(转)

    英文可查:地址 1.SoftmaxWithLoss 对一对多的分类任务计算多项逻辑斯蒂损失,并通过softmax传递预测值,来获得各类的概率分布.该层可以分解为SoftmaxLayer+Multino ...

  6. Happy Matt Friends(HDU5119 + dp)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5119 题目: 题意: 求选择任意个数,使其异或和大于等于m的方案数. 思路: 每个数有选和不选两种方 ...

  7. Django 基础命令

  8. MUI上拉加载下拉刷新

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. [转]ROS(Robot Operating System)常用环境变量介绍

    本文简单介绍ROS系统中常用的环境变量用途及设置方式.ROS系统环境中除了必须配置的环境变量以外,其他的也是十分有用,通过修改变量路径,可以设置ROS系统中log文件存放路径,单元测试结果存放路径等. ...

  10. springcloud中eureka集群unavailable-replicas

    unavailable-replicas 配置了集群,但是在注册中心显示另外的几个集群地址是不可用的: 1 首先需要再host中添加服务名映射,如果应映射了再看是否在yml中配置了prefer-ip- ...