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 ≤ ...
随机推荐
- 转:iOS绘制一个UIView
绘制一个UIView 绘制一个UIVIew最灵活的方式就是由它自己完成绘制.实际上你不是绘制一个UIView,你只是子类化了UIView并赋予子类绘制自己的能力.当一个UIVIew需要执行绘图操作的时 ...
- 解决错误:Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
在使用yum install的时候,偶尔会碰见这样的错误:Couldn’t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 这是因为在你的 /etc/yum ...
- java字节码文件 helloworld
Java代码 \\A.java public class A{} 1 2 1 2 javac A.java \\得到 A.class javap -v A.class 下面是javap工具帮我们生成的 ...
- bzoj千题计划173:bzoj1257: [CQOI2007]余数之和sum
http://www.lydsy.com/JudgeOnline/problem.php?id=1257 k%i=k-int(k/i)*i 除法分块,对于相同的k/i用等差序列求和来做 #includ ...
- Throwable、Error、Exception、RuntimeException 区别
1.java将所有的错误封装为一个对象,其根本父类为Throwable, Throwable有两个子类:Error和Exception. 2.Error是Throwable 的子类,用于指示合理的应用 ...
- 【leetcode 简单】 第一百一十题 分发饼干
假设你是一位很棒的家长,想要给你的孩子们一些小饼干.但是,每个孩子最多只能给一块饼干.对每个孩子 i ,都有一个胃口值 gi ,这是能让孩子们满足胃口的饼干的最小尺寸:并且每块饼干 j ,都有一个尺寸 ...
- Ubuntu 通过 Live CD 更新grub恢复引导Boot Menu
工作需要更换主板,但是不想重装电脑. 怎么办呢? 其实并不需要重装电脑,只需要回复boot menu即可. 1. 首先用u盘制作一个ubuntu的live CD(请自行百度),然后通过u盘启动, 选择 ...
- 2016.6.19——C++杂记
C++杂记 补充的小知识点: 1.while(n--)和while(--n)区别: while(n--)即使不满足也执行一次循环后跳出. while(--n)不满足直接跳出循环,不执行语句. 用cou ...
- Java中关于变量的几种情况
Java中关于变量的几种情况 1.继承时变量的引用关系 class Animals { int age = 10; void enjoy() { System.out.println("An ...
- Shell中三种引号的用法及区别
Linux Shell中有三种引号,分别为双引号(" ").单引号(' ')以及反引号(` `). 其中双引号对字符串中出现的$.''.`和\进行替换:单引号不进行替换,将字符串中 ...