zoj 2770 Burn the Linked Camp
今天刚刚学差分约束系统。利用最短路求解不等式。世界真的好奇妙!感觉不等式漏下几个会导致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的更多相关文章
- ZOJ 2770 Burn the Linked Camp 差分约束
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemCode=2770 Burn the Linked Camp Time Limi ...
- ZOJ 2770 Burn the Linked Camp 差分约束 ZOJ排名第一~
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1770 题目大意: 陆逊为了火烧连营七百里,派出了间谍刺探敌情,得之刘备的军营以 ...
- zoj 2770 Burn the Linked Camp (差分约束系统)
// 差分约束系统// 火烧连营 // n个点 m条边 每天边约束i到j这些军营的人数 n个兵营都有容量// Si表示前i个军营的总数 那么 1.Si-S(i-1)<=C[i] 这里 建边(i- ...
- ZOJ 2770 Burn the Linked Camp(spfa&&bellman)
//差分约束 >=求最长路径 <=求最短路径 结果都一样//spfa#include<stdio.h> #include<string.h> #include< ...
- zoj Burn the Linked Camp (查分约束)
Burn the Linked Camp Time Limit: 2 Seconds Memory Limit: 65536 KB It is well known that, in the ...
- Burn the Linked Camp(bellman 差分约束系统)
Burn the Linked Camp Time Limit: 2 Seconds Memory Limit: 65536 KB It is well known that, in the ...
- ZOJ2770 Burn the Linked Camp(差分约束系统)
区间和一定要联系到前缀和. 这题,把前缀和看作点,从s0到sn: 对于每一个营地i的容量capi,有这么个关系si-si-1<=capi: 对于每一个区间的评估i,j,k,有sj-si-1> ...
- zoj2770 Burn the Linked Camp --- 差分约束
有n个营地,每一个营地至多容纳Ci人.给出m个条件:第i到第j个营地之间至少有k人. 问n个营地总共至少有多少人. 此题显然差分约束.要求最小值.则建立x-y>=z方程组,建图求最长路. 用d[ ...
- ZOJ 2770 差分约束+SPFA
Burn the Linked Camp Time Limit: 2 Seconds Memory Limit: 65536 KB It is well known that, in the ...
随机推荐
- PRD学习笔记:一些需要注意的说明
控件说明 1)输入框 若输入框有默认提示,点击输入框,弹出软键盘. 当输入框内不为空(空格除外)时,默认显示消失. 2)软键盘的弹出及退去机制 当输入框内必须输入的为数字时,弹出数字软键盘.其余时候, ...
- Netty 5.0源码分析-Bootstrap
1. 前言 io.netty.bootstrap类包提供包含丰富API的帮助类,能够非常方便的实现典型的服务器端和客户端通道初始化功能. 包含的接口类: //提供工厂类的newChannel方法创建一 ...
- Putty的注册表设置
Putty是一款非常好用的远程管理Linux系统的工具,其主要具有以下几个优点: 完全免费; 在Windows 9x/NT/2000下运行的都非常好; 全面支持SSH1和SSH2: 绿色软件, ...
- STM32 Keil查看程序占用ROM和RAM
1. 编译生成的map文件中code , RO ,RW, ZI 表示内容 Code为程序代码部分 RO-data 表示 程序定义的常量const temp; RW-data 表示 已初始化的全局变量 ...
- c#计算datatable中某一列值的和
double sumPercentage = dt.AsEnumerable().Where(dr => { return dt.Rows.IndexOf(dr) > 0; }).Sum( ...
- ecshop3.0.0注入
配个环境来演示给别人看..分析一下.flow.php文件缺陷,order_id在post请求没有单引号保护.造成注入 <?php elseif ($_REQUEST['step'] == 're ...
- U31网管配置
1.新建网元和子架配置: 在拓扑图空白处新建对象-创建承载传输网元-选择设备-填写网元名称(A).网元类型.IP(查询出SNP的),网关IP会自动在此基础上加2.如果数据库为空先选离线- 机架子架配置 ...
- shrio初体验(2)Realm
Realm:域,Shiro从从Realm获取安全数据(如用户.角色.权限),就是说SecurityManager要验证用户身份,那么它需要从Realm获取相应的用户进行比较以确定用户身份是否合法:也需 ...
- 运行ORB-SLAM笔记_编译篇(一)
1.下载代码 https://github.com/raulmur/ORB_SLAM/ (同时也可以看看作者的牛叉论文,我是打算先用代码,再回头看论文) 2.打开后如下 就好像是用一件新产品 ...
- 创建 userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置节处理程序时出错: 未能加载文件或程序集“System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”或它的某一个依赖项。系统没找到指定的文件
创建 userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置节处理程序时出错: 未能加载文 ...