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. Java RMI 简单实现

    提供远端访问的时候,我们首先需要定义远端能够访问哪些东西,在Java中,定义这类接口需要实现Remote接口 public interface Business extends Remote{ pub ...

  2. java字节码文件 helloworld

    Java代码 \\A.java public class A{} 1 2 1 2 javac A.java \\得到 A.class javap -v A.class 下面是javap工具帮我们生成的 ...

  3. JavaApplet-Application Blocked..Your security setting have blocked an untrusted application from running..

    From:http://www.cnblogs.com/killerlegend/p/3892668.html Author:KillerLegend Date:2014.8.5 在看A*算法的时候, ...

  4. vue 脚手架使用

    1. npm指令 vue init 模板类型   项目名称 如: vue init webpack-simple mydemo 2.进入刚才生产的 文件夹 mydemo cd mydemo 3.初始化 ...

  5. Android 使用GPS获取到经纬度后 无法在Android8.0上使用Geocoder类获取位置信息

    由于我的应用在获取到经纬度后在Android8.0不能使用如下代码获取位置信息.只好使用百度地图 WEB服务API 通过调接口的方式获取位置信息. Geocoder geocoder = new Ge ...

  6. 贪心问题:区间覆盖 NYOJ 喷水装置(二)

    喷水装置(二) 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 有一块草坪,横向长w,纵向长为h,在它的橫向中心线上不同位置处装有n(n<=10000)个点状的喷水 ...

  7. Django 2.0.1 官方文档翻译: 编写你的第一个 Django app,第三部分(Page 8)

    编写你的第一个 Django app,第三部分(Page 8)转载请注明链接地址 本页教程接前面的第二部分.我们继续开发 web-poll app,我们会专注于创建公共接口上 -- "视图& ...

  8. ETL测试基本知识

    转载自: https://www.cnblogs.com/clarke157/p/6383024.html 一.ETL测试的重要性: ETL(Extract-Transform-Load的缩写,即数据 ...

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

    20155330 2016-2017-2 <Java程序设计>第七周学习总结 教材学习内容总结 学习目标 了解Lambda语法 了解方法引用 了解Fucntional与Stream API ...

  10. 介绍一个强大的画图类 CImage(转)

    我们知道,Visual C++的CBitmap类和静态图片控件的功能是比较弱的,它只能显示出在资源中的图标.位图.光标以及图元文件的内容,而不像VB中的Image控件可以显示出绝大多数的外部图像文件( ...