题意:

给定每个兵营的最大容量,以及第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. 萌新--关于vue.js入门及环境搭建

    十几天闭关修炼,恶补了html跟css以及JavaScript相应的基础知识,恰巧有个群友准备做开源项目,愿意带着我做,但是要求我必须懂vue.js,所以开始恶补vue.js相关的东西. 在淘宝上买了 ...

  2. R Programming week1-Reading Data

    Reading Data There are a few principal functions reading data into R. read.table, read.csv, for read ...

  3. Farseer.net轻量级开源框架 中级篇:SQL执行报告

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 中级篇: 数据库切换 下一篇:Farseer.net轻量级开源框架 中级篇: 探究ORM(M ...

  4. 物联网初学者智能家居必备迅为iTOP-4412开发板

    更情点击了解:http://www.topeetboard.com 1.  手把手全视频教程: 第一部分:迅为电子开发板入门视频 第二部分:Linux系统编程 第三部分:Itop-4412开发板硬件设 ...

  5. python_MachineLearning_感知机PLA

    感知机:线性二类分类器(linear binary classifier)   感知机(perceptron)是二类分类的线性模型,其输入为实例的特征向量,输出为实例的类别,取+1和-1二值.感知机对 ...

  6. Android(java)学习笔记195:ContentProvider使用之添加数据到联系人(掌握)

    1.添加联系人逻辑思路 (1)首先在raw_contacts创建一个新的id (2)在data表里面添加这个id对应的数据 2.下面通过一个案例,说明一下如何添加一条数据到联系人: (1)首先我们关注 ...

  7. sql 语句的优化

    sql语句的优化:在大多数情况下,为了更快的遍历表结构,优化器主要是根据定义的索引来提高性能.但是在不合理的SQL语句中,优化器会删去索引进而使用全表扫描, 一般而言,这种sql被称为劣质sql,所以 ...

  8. CSS 文字换行与不换行

    1. 强制不换行 p{ white-space:nowrap; } 2. 自动换行 p{ word-wrap: break-word; word-break: normal; } 3. 强制英文单词断 ...

  9. cf536b——优先队列的运用

    题目 题目:cf536 B题 题目大意:一个饭店有n种食物,每种食物有对应的价格和数量,然后有m个顾客,每个顾客需要$d_j$份第$t_j$种食物,如果该种食物数量不够,则选其它尽可能便宜的代替(出现 ...

  10. webgl 的空间变换(下):空间变换

    在网上看了很多关于在三维世界中怎么把一个顶点经过一步步变化,最终呈现在我们的屏幕上的. 其实很多博客或者书籍已经讲的很清楚了,那为什么我还要特别再写一次博客来阐述自己观点呢?(这里只针对那些学习web ...