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

#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std; const int maxn = ;
vector<int>ljb[maxn];//邻接表
int jz[maxn][maxn];//邻接矩阵
int n, m, shibai;
int c[maxn], d[maxn];
int dist[maxn];
int flag[maxn], tott[maxn]; void spfa()
{
int ii;
queue<int>Q;
memset(flag, , sizeof(flag));
memset(tott, , sizeof(tott));
flag[n] = ; tott[n]++;
for (ii = ; ii <= n; ii++) dist[ii] = ;
dist[n] = ; Q.push(n);
while (!Q.empty())
{
int hh = Q.front(); Q.pop(); flag[hh] = ;
for (ii = ; ii < ljb[hh].size(); ii++)
{
if (jz[hh][ljb[hh][ii]] != )
{
if (dist[hh] + jz[hh][ljb[hh][ii]] < dist[ljb[hh][ii]])
{
dist[ljb[hh][ii]] = dist[hh] + jz[hh][ljb[hh][ii]];
if (flag[ljb[hh][ii]] == )
{
Q.push(ljb[hh][ii]);
flag[ljb[hh][ii]] = ;
tott[ljb[hh][ii]]++;
if (tott[ljb[hh][ii]] >= n) { shibai = ; break; }
}
}
}
}
if (shibai) break;
}
} int main()
{
int i, j, u, v, k;
while (~scanf("%d%d", &n, &m))
{
shibai = ; c[] = ; d[] = ;
for (i = ; i <= n; i++) ljb[i].clear();
for (i = ; i <= n; i++)
{
for (j = ; j <= n; j++)
{
if (i == j) jz[i][j] = ;
else jz[i][j] = ;
}
}
for (i = ; i <= n; i++) scanf("%d", &c[i]);
for (i = ; i <= n; i++) d[i] = c[i] + d[i - ];
for (i = ; i < m; i++)
{
scanf("%d%d%d", &v, &u, &k);
jz[u][v - ] = -k;
ljb[u].push_back(v - );
jz[v - ][u] = d[u] - d[v - ];
ljb[v - ].push_back(u);
}
for (i = ; i <= n; i++)
{
jz[i - ][i] = c[i];
ljb[i - ].push_back(i);
jz[i][i - ] = ;
ljb[i].push_back(i - );
}
spfa();
if (shibai == ) printf("Bad Estimations\n");
else printf("%d\n", -dist[]);
}
return ;
}

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 (差分约束系统)

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

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

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

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

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

  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. ZOJ2770 Burn the Linked Camp(差分约束系统)

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

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

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

  9. ZOJ 2770 差分约束+SPFA

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

随机推荐

  1. Angularjs通过$http与服务器通信

    angular是一个前端框架,实现了可交互式的页面,但是对于一个web应用,页面上进行展示的数据从哪里来,肯定需要服务端进行支持,那么angular是如何同服务端进行交互的呢? $http angul ...

  2. Largest prime factor

    problem 3:Largest prime factor 题意:求600851475143的最大的质因数 代码如下: #ifndef PRO3_H_INCLUDED #define PRO3_H_ ...

  3. mongodb tip-2

    1.or 查询的格式: var condition = {$or:[{field:1},{field:2}]} 2.字符串存储日期也可以用$gt $gte $lt $lte 直接比较 var cond ...

  4. CentOS部署yum本地源和共享

    约定yum本地源的机器IP为192.168.1.100,需要访问共享源的IP为192.168.1.101 关闭并禁止selinux和firewalld 创建本地源 1.上传centos7光盘镜像到指定 ...

  5. solr常用命令

    1.启动和关闭 a.启动和重启 启动和重启命令有很多选项让你运行在SolrCloud模式,使用示例配置,以hostname为开头或者非默认端口,指向本地ZooKeeper. bin/solr star ...

  6. java自带的监控工具VisualVM一

    转自:http://www.cnblogs.com/wade-xu/p/4369094.html 这篇总结的很不错(本人亲自操手学习),留着以后复习备用,很适合入门级的学习者: VisualVM 是一 ...

  7. Web前端优质学习网站

    * 官方:           W3C:http://www.w3.org/           ECMA:http://www.ecmascript.org/           Mozilla:h ...

  8. Android设置窗体Activity背景透明

    背景透明 style.xml <item name="android:windowBackground">@color/transparent</item> ...

  9. shell-改变分隔符

    转化为换行符: oldIFS=${IFS}; IFS=$'\n'; 命令; IFS=${oldIFS};

  10. 安卓activity之间值共享解决办法,tabhost之间共享父类值,字符串类型的转换,获取每一个listview的item

    1.tabhost父类值共享的解决办法 dianzhanliebiao.java是传值页面,zhuyemian.java放的是tabhost,dianzhangaikuang.java是tabhost ...