题意:

给定每个兵营的最大容量,以及第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的更多相关文章

  1. zoj Burn the Linked Camp (查分约束)

    Burn the Linked Camp Time Limit: 2 Seconds      Memory Limit: 65536 KB It is well known that, in the ...

  2. ZOJ 2770 Burn the Linked Camp 差分约束

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemCode=2770 Burn the Linked Camp Time Limi ...

  3. Burn the Linked Camp(bellman 差分约束系统)

    Burn the Linked Camp Time Limit: 2 Seconds      Memory Limit: 65536 KB It is well known that, in the ...

  4. ZOJ 2770 Burn the Linked Camp 差分约束 ZOJ排名第一~

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1770 题目大意: 陆逊为了火烧连营七百里,派出了间谍刺探敌情,得之刘备的军营以 ...

  5. zoj 2770 Burn the Linked Camp (差分约束系统)

    // 差分约束系统// 火烧连营 // n个点 m条边 每天边约束i到j这些军营的人数 n个兵营都有容量// Si表示前i个军营的总数 那么 1.Si-S(i-1)<=C[i] 这里 建边(i- ...

  6. ZOJ 2770 Burn the Linked Camp(spfa&&bellman)

    //差分约束 >=求最长路径 <=求最短路径 结果都一样//spfa#include<stdio.h> #include<string.h> #include< ...

  7. zoj 2770 Burn the Linked Camp

    今天刚刚学差分约束系统.利用最短路求解不等式.世界真的好奇妙!感觉不等式漏下几个会导致WA!! #include<cstdio> #include<cstring> #incl ...

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

  9. ZOJ2770 Burn the Linked Camp(差分约束系统)

    区间和一定要联系到前缀和. 这题,把前缀和看作点,从s0到sn: 对于每一个营地i的容量capi,有这么个关系si-si-1<=capi: 对于每一个区间的评估i,j,k,有sj-si-1> ...

随机推荐

  1. java 缓冲流 Buffer

    缓冲流 Buffer :设置缓冲区加快执行效率 子类: (一)BufferedInputStream : 缓冲输入字节流 ,目的:提高读取文件的效率  注意: BufferedInputStream ...

  2. Hadoop YARN学习之组件功能简述(3)

    Hadoop YARN学习之组件功能简述(3) 1. YARN的三大组件功能简述: ResourceManager(RM)是集群的资源的仲裁者, 它有两部分:一个可插拔的调度器和一个Applicati ...

  3. Django model 反向引用中的related_name

    转自:https://blog.csdn.net/lanyang123456/article/details/68962515 问题: 定义表Apple: class Apple( models.Mo ...

  4. iOS Programming UIGestureRecognizer and UIMenuController

    iOS  Programming  UIGestureRecognizer and UIMenuController A UIGestureRecognizer intercepts touches ...

  5. Java对Redis基本使用

    1 引入jar包 java是通过Jedis对redis进行操作的,首先引入jedis.jar <dependency> <groupId>redis.clients</g ...

  6. 8086汇编——Introduction(8086内部寄存器,段寄存器,存储器分段)

    8086汇编--Introduction 一.8086CPU的三种工作模式 实模式:只有低20位地址线起作用,仅能寻址第一个1MB的内存空间.MS DOS运行于该模式下. 保护模式:在该模式下,机器可 ...

  7. Day3 CSS 引入及基本选择器

    一 .CSS 层叠样式表,为了使网页元素的样式更加丰富,内容与样式拆分开来.HTML负责结构与内容,表现形式交给CSS. CSS注释/**/ 来注释 二.CSS基本语法与引用 CSS的语法结构 选择器 ...

  8. hibernate inverse属性

    修改街道对应的区道信息: 修改后会发现程序执行了两次修改操作: 原因: 区道与街道是一对多的关系: 由于Hibernate是双向维护外键,所以当修改区道中的街道时,会修改一次外键:在修改街道中的区道时 ...

  9. 08CSS边框边距

    CSS边框边距 边框样式——border-style border-top-style border-bottom-style border-left-style border-right-style ...

  10. SVN文件库移植(转)

     SVN文件库移植(转) 分类: 项目管理2013-04-19 11:06 161人阅读 评论(0) 收藏 举报 公司以前用的SVN是安装在windows2003下,用了一年多,现在大家觉得很慢,强烈 ...