// 差分约束系统
// 火烧连营
// n个点 m条边 每天边约束i到j这些军营的人数 n个兵营都有容量
// Si表示前i个军营的总数 那么 1.Si-S(i-1)<=C[i] 这里 建边(i-1,i) 权值为 C[i]
// 2.S(i-1)-Si<=0 这里 建边(i,i-1) 权值为 0
// 3.S(j)-S(i-1)>=k => S(i-1)-Sj<=-k 这里建边 (j,i-1) 权值为 -k
// 题目求的事 Sn-S0的最小值 Sn-S0>=m 中符合条件的m最大值就是答案
// 等价 S0-Sn<=-m 求点 Sn 到 S0的最小值 就是求最短路径 (这里可能不好理解,需要慢慢体会)
// #include <iostream>
#include <map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
#define MOD 1000000007
#define maxn 20010 // 开始我天真了 maxn=10010 和 m 差不错大 WA的好难过 图中边数应该为 m+2n
#define MAX 100000000
struct node{
int to;
int next;
int val;
}E[maxn];
int num;
int V[];
int C[];
int d[],cnt[];
bool f[];
bool sfpa(int s,int t){// s既表示起点 又表示节点个数
queue <int> Q;
int u,v;
int e;
Q.push(s);
d[s]=;
f[s]=true;
while(!Q.empty()){
u=Q.front(); Q.pop();
cnt[u]++;
if(cnt[u]>s) return false;
f[u]=false;
for(e=V[u];e!=-;e=E[e].next){
v=E[e].to;
if(d[u]+E[e].val<d[v]){
d[v]=d[u]+E[e].val;
if(!f[v])
{
f[v]=true;
Q.push(v);
}
}
}
}
return true;
}
int main(){
int i,j,k;
int n,m;
while(scanf("%d %d",&n,&m)!=EOF){
for(i=;i<=n;i++)
{
scanf("%d",&C[i]);
V[i]=-;
d[i]=MAX;
cnt[i]=;
f[i]=false;
}
num=;
i=;
V[i]=-;
d[i]=MAX;
cnt[i]=;
f[i]=false;
while(m--){
scanf("%d %d %d",&i,&j,&k);
E[num].to=i-;
E[num].val=-k;
E[num].next=V[j];
V[j]=num++;
}
for(i=n;i>=;i--){
E[num].to=i;
E[num].val=C[i];
E[num].next=V[i-];
V[i-]=num++;
E[num].to=i-;
E[num].val=;
E[num].next=V[i];
V[i]=num++;
}
if(sfpa(n,))
printf("%d\n",-d[]);
else
printf("Bad Estimations\n"); } }

zoj 2770 Burn the Linked Camp (差分约束系统)的更多相关文章

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

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

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

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

  3. zoj 2770 Burn the Linked Camp

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

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

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

  5. zoj2770 Burn the Linked Camp --- 差分约束

    有n个营地,每一个营地至多容纳Ci人.给出m个条件:第i到第j个营地之间至少有k人. 问n个营地总共至少有多少人. 此题显然差分约束.要求最小值.则建立x-y>=z方程组,建图求最长路. 用d[ ...

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

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

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

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

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

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

  9. ZOJ 2770 差分约束+SPFA

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

随机推荐

  1. 20160727noip模拟赛zld

    首先最优策略肯定是这样的:我们取出这个序列中的最大值,然后将整个序列分为左右两部分, 那么我们一定先把左右两部分合起来然后再与这个值合并 那么我们可以得出一个基于最值查询(rmq)的的算法,但是zld ...

  2. 【转】System.DateTime.Now.ToString()的一些用法

    C#中的日期处理函数     //2007年4月24日     this.TextBox6.Text = System.DateTime.Now.ToString("D");    ...

  3. PHP杂记

    SOAP: 感觉是类似于Java中的HttpClient的东西,和curl也有点像. PHPStorm中查看所有的函数结构(Structure):Alt+7 查找方法或类(Symbol Name 函数 ...

  4. [转载]Spring Bean Definition Inheritance

    Following is the configuration file Beans.xml where we defined "helloWorld" bean which has ...

  5. 【转】Wireshark:“There are no interfaces on which a capture can be done ”

    linux环境下 两种解决方案:    第一种方法:使用root用户登陆        xiaoshancun@xiaoshancun-VM500:~$ sudo wireshark    第二种方法 ...

  6. 李洪强iOS开发之 - 实现九宫格并使用SDWebImage下载图片

     李洪强iOS开发之 - 实现九宫格并使用SDWebImage下载图片  源码:  // //  ViewController.m //  08-九宫格扩展 // //  Created by 李洪强 ...

  7. Unity UGUI —— 鼠标穿透UI问题(Unity官方的解决方法)

    解决方案 : http://www.cnblogs.com/fly-100/p/4570366.html 这里我们直接在使用Input.GetMouseButtonDown(0)的地方加了一个检测函数 ...

  8. C#四种文件流的区别(转)

    1.FileStream类的读写操作 FileStream类可以对任意类型的文件进行读取操作,而且我们也可以按照需要指定每一次读取字节长度,以此减少内存的消耗,提高读取效率. 代码实例: //创建文件 ...

  9. C++:类的创建

    类的创建 #include<iostream> #include<cmath> using namespace std; class Complex //声明一个名为Compl ...

  10. Linux Shell脚本入门:tee命令

    用途说明   在执行Linux命令时,我们可以把输出重定向到文件中,比如 ls >a.txt,这时我们就不能看到输出了,如果我们既想把输出保存到文件中,又想在屏幕上看到输出内容,就可以使用tee ...