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. mongodb3.6集群搭建:分片集群认证

    上篇集群已经创建,现在加入认证. 1. 生成密钥文件每个服务器上创建路径: mkdir -p /var/lib/mongo/auth 生成64字节的密钥文件openssl rand -base64 6 ...

  2. Linux基础实验

    过滤,管道与重定向 过滤 管道 重定向 运维常用 给某目录设置权限 sudo chmod -R /var/www/html/

  3. openresty/1.11.2.1性能测试

    测试数据 ab -n -c -k http://127.0.0.1/get_cache_value nginx.conf lua_shared_dict cache_ngx 128m; server ...

  4. iOS二维码扫描的实现(Swift)

    随着二维码的普遍使用,二维码扫描也成为了很多app的一个基本功能,本篇主要来介绍一下如何实现一个简单的二维码扫描功能.本文使用了XCode自带的AVFoundation 库,利用Swfit语言实现. ...

  5. [转载]如何做到 jQuery-free?

    http://www.ruanyifeng.com/blog/2013/05/jquery-free.html jQuery是现在最流行的JavaScript工具库. 据统计,目前全世界57.3%的网 ...

  6. [整理]ASP.NET vNext学习资源

    http://www.hanselman.com/blog/IntroducingASPNETVNext.aspx http://blogs.msdn.com/b/dotnet/archive/201 ...

  7. 20155307 2016-2017-2 《Java程序设计》第七周学习总结

    学号 2016-2017-2 <Java程序设计>第七周学习总结 教材学习内容总结 认识Lambda语法,方法参考在重用现有API上扮演了重要角色,重用现有方法操作,可避免到处写下Lamb ...

  8. HDU 1256 画8 模拟题

    解题报告:这题我觉得题目有一个没有交代清楚的地方就是关于横线的字符的宽度的问题,题目并没有说,事实上题目要求的是在保证下面的圈高度不小于上面的圈的高度的情况下,横线的宽度就是等于下面的圈的高度. #i ...

  9. HDU 2094 产生冠军 dfs加map容器

    解题报告:有一群人在打乒乓球比赛,需要在这一群人里面选出一个冠军,现在规定,若a赢了b,b又赢了c那么如果a与c没有比赛的话,就默认a赢了c,而如果c赢了a的话,则这三个人里面选不出冠军,还有就是如果 ...

  10. 去除zabbix calculate 模式下,有时候分母为零的情况(Cannot evaluate expression: division by zero. )

    zabbix的监控类型支持一种calculate的方式,可以对几个item结果进行简单的计算,但有时会出现分母为零的情况,这时候监控项就会报错 Cannot evaluate expression: ...