ZOJ 2770_Burn the Linked Camp
2016-02-12 09:37
435 查看
题意:
给定每个兵营的最大容量,以及第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 = 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 -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
- 从贝叶斯方法谈到贝叶斯网络
- poj1154(大水题)
- 创业的第一百一十八天
- native Qt signal is not callable
- 关于使用Genymotion被墙的临时解决方案
- 【C语言】C语言关键字
- 【Python】python对象与json相互转换
- JavaScript判断表单为空及获取焦点的方法
- Ubuntu14.04 LTS更新源
- Transitioning From Kali 2.0 to Kali Rolling
- FreeRTOS系列第15篇---使用任务通知实现命令行解释器
- 使用原生方法从kafka消费消息
- android 半orm 数据库框架(dileber数据库框架)
- 从头认识Spring-2.2 默认自动装配
- Web开发人员常犯的10个错误
- 使用 Code Snippet 简化 Coding
- ubuntu命令行打开html文件的方法
- difference between abstract class and interface
- 抽象类与接口的构造方法