题意:

给定每个兵营的最大容量,以及第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. WinForm 对话框,流

    private void button1_Click(object sender, EventArgs e) { //显示颜色选择器 colorDialog1.ShowDialog(); //把取到的 ...

  2. Java 线程实例 刷碗烧水和倒计时

    线程——烧水刷碗和倒计时实例 (一)烧水刷碗 刷碗的同时烧水:下面是碗的程序: 下面是烧水的程序:在水的实现类中,调用了Thread线程,让烧水刷碗同时进行. 注意:刷碗2s一次,烧水10s (二)1 ...

  3. 2017.5.20欢(bei)乐(ju)赛解题报告

    预计分数:100+20+50=first 实际分数:20+0+10=gg 水灾(sliker.cpp/c/pas) 1000MS  64MB 大雨应经下了几天雨,却还是没有停的样子.土豪CCY刚从外地 ...

  4. npm run dev报错--Error: Cannot find module 'yargs-parser'

    Error: Cannot find module 'yargs-parser'  ---报错不知何解??? 百度了很久没找到方法,是缺少“ yargs-parser ”模块,需要安装一下即可:cnp ...

  5. R58的编译步骤f1选项v1.1版本

    R58的编译步骤f1选项v1.1版本 2017/3/16 16:38 请严重注意: 编译全志R58的Android6.0.1的系统和其它系统有两个不同: 1.在执行pack打包之前,必须执行verit ...

  6. Android SDK镜像更新网速慢的解决问题

    通过更换代理解决 Android SDK 在线更新镜像服务器资源:大连东软信息学院镜像服务器地址:http://mirrors.neusoft.edu.cn 端口:80北京化工大学镜像服务器地址:IP ...

  7. SQLServer性能优化专题

    SQLServer性能优化专题 01.SQLServer性能优化之----强大的文件组----分盘存储(水平分库) http://www.cnblogs.com/dunitian/p/5276431. ...

  8. dll、lib(动态链接库、静态链接库)的区别

    1.dll:dynamic link library: lib:static link library. 2.windows系统中,许多app并不是仅由一个完整的exe构成,而是按功能分成了若干部分, ...

  9. sh NonUniqueObjectException

    话题引入: 使用hibernate进行更新操作时,首先调用了findById方法获取要修改的对象,此时session没有被关闭,接着重新创建一个对象,将要修改的属性值赋值给这个对象.调用修改方法抛出如 ...

  10. centos7 安装后,意外出现Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]

    安装完成centos7后出现如下提示: Initial setup of CentOS Linux 7 (core) 1) [x] Creat user 2) [!] License informat ...