ZOJ 2770_Burn the Linked Camp
题意:
给定每个兵营的最大容量,以及第i到第j个兵营至少有多少个士兵,问所有兵营一共至少有多少个士兵?
分析:
差分约束系统,注意
- 第i到第j至少有k个
- 第i到第j最多有最大容量之和个
- 每个兵营至少有0个
- 每个兵营最多有最大容量个
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
#define mem(s,a) memset(s, a, sizeof(s))
typedef long long ll;
const int maxm = 25005, maxn = 1005;
#define INF 0x3ffffffff
struct edge{int u,v;ll w;};
edge e[maxm];
int c[maxn];
long long d[maxn];
int m, n, tot;
bool bellford()
{
fill(d,d+n+1,INF);
d[n] = 0;
for(int i = 0; i < n + 1; i++){
for(int j = 0; j < tot; j++){
int u1= e[j].u, v1 = e[j].v;
if(d[u1]!=INF&&d[v1]-d[u1]>e[j].w){
d[v1] = d[u1] + e[j].w;
if(i == n) return false;
}
}
}
return true;
}
int main (void)
{
int t;
while(~scanf("%d%d",&n, &m)){
mem(c,0);
for(int i = 1; i <= n; i++){
scanf("%d",&t);
c[i] = c[i-1] +t;
}
int i, j, k;
tot = 0;
for(int a = 0; a < m; a++){
scanf("%d%d%d",&i,&j,&k);
e[tot++] = (edge){j, i-1, -k};
e[tot++] = (edge){i-1, j, c[j]-c[i-1]};
}
for(int b= 0; b < n; b++){
e[tot++] = (edge){b, b + 1, c[b + 1] - c[b]};
e[tot++] = (edge){b+1, b, 0};
}
if(bellford()) printf("%I64d\n",d[n]-d[0]);
else printf("Bad Estimations\n");
}
return 0;
}
之前一直怕k会很大,就用了long long,可是INF忘记改,一直PE,后来改了INF,AC,改成int,AC,可是到现在也不明白为什么是PE而不是WA。
先放着再想想吧。
ZOJ 2770_Burn the Linked Camp的更多相关文章
- zoj Burn the Linked Camp (查分约束)
Burn the Linked Camp Time Limit: 2 Seconds Memory Limit: 65536 KB It is well known that, in the ...
- ZOJ 2770 Burn the Linked Camp 差分约束
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemCode=2770 Burn the Linked Camp Time Limi ...
- Burn the Linked Camp(bellman 差分约束系统)
Burn the Linked Camp Time Limit: 2 Seconds Memory Limit: 65536 KB It is well known that, in the ...
- ZOJ 2770 Burn the Linked Camp 差分约束 ZOJ排名第一~
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1770 题目大意: 陆逊为了火烧连营七百里,派出了间谍刺探敌情,得之刘备的军营以 ...
- zoj 2770 Burn the Linked Camp (差分约束系统)
// 差分约束系统// 火烧连营 // n个点 m条边 每天边约束i到j这些军营的人数 n个兵营都有容量// Si表示前i个军营的总数 那么 1.Si-S(i-1)<=C[i] 这里 建边(i- ...
- ZOJ 2770 Burn the Linked Camp(spfa&&bellman)
//差分约束 >=求最长路径 <=求最短路径 结果都一样//spfa#include<stdio.h> #include<string.h> #include< ...
- zoj 2770 Burn the Linked Camp
今天刚刚学差分约束系统.利用最短路求解不等式.世界真的好奇妙!感觉不等式漏下几个会导致WA!! #include<cstdio> #include<cstring> #incl ...
- ZOJ2770-Burn The Linked Camp(火烧连营Orz 差分约束-线性约束+最长路(OR反向最短路))
It is well known that, in the period of The Three Empires, Liu Bei, the emperor of the Shu Empire, w ...
- ZOJ2770 Burn the Linked Camp(差分约束系统)
区间和一定要联系到前缀和. 这题,把前缀和看作点,从s0到sn: 对于每一个营地i的容量capi,有这么个关系si-si-1<=capi: 对于每一个区间的评估i,j,k,有sj-si-1> ...
随机推荐
- 可以装一把——c#中手动添加控件
TextBox txt = new TextBox(); //文本框控件 //如果想在移动控件位置 point(x,y) txt.Location = new Point(50,50); this.C ...
- java之数据处理,小数点保留位数
1.返回字符串类型,保留后两位: public static String getRate(Object d) { return String.format("%.2f", d); ...
- 简洁大方的wordpress主题,不容错过的主题,附带主题源码下载
cu主题是由疯狂的大叔设计,界面简洁大方是它最大的特点之一. 手残君也比较喜爱这款主题,在使用的过程中,根据手残君的个人习惯,对其进行了优化. 标题优化 标题居中显示 增加标题div背景色 标题div ...
- 《基于Node.js实现简易聊天室系列之总结》
前前后后完成这个聊天室的Demo花了大概一个星期,当然一个星期是仅仅指编码的工作.前期的知识储备是从0到1从无到有,花费了一定的时间熟悉Node.js的基本语法以及Node.js和mongoDB之间的 ...
- [小记]Android缓存问题
今天晚上,产品经理打电话说我们的Android App除了问题,问题很简单就是一个缓存问题,由于这个程序是前同事写的,我也只能呵呵一笑,有些事你就得扛.还是回到正题吧,这个缓存问题,实在有点奇葩,所以 ...
- discuz 插件核心函数hookscript分析.
function hookscript($script, $hscript, $type = 'funcs', $param = array(), $func = '', $scriptextra = ...
- JVM中常见的垃圾收集器
垃圾收集机制是 Java 的招牌能力,极大地提高了开发效率.如今,垃圾收集几乎成为现代语言的标配,即使经过如此长时间的发展, Java 的垃圾收集机制仍然在不断的演进中,不同大小的设备.不同特征的应用 ...
- java线程学习2
sleep 变为阻塞态 但不释放锁 休眠指定毫秒时间 yield 变为就绪态 可能立即被执行 也可能不立即被执行 join 插队 暂停当前执行的线程 让调用join的线程先执行 线 ...
- anchor box聚类
fast rcnn和rfcn中使用的都是默认的anchor box设置,都是9种,比例为0.5 .1. 2,大小为128.256.512.但我的数据集的gt框更小,需要找到适合我的数据集的anchor ...
- Webstorm 的 Tab 键调整缩进值
两步即可,注意版本