差分约束系统。

求最小值,用最长路来解决。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std; const int maxn=;
const int INF=0x7fffffff;
struct abc
{
int startt;
int endd;
int costt;
} node[*maxn];
vector<abc>ljb[maxn];
int tott,n,zd,zx;
int dist[maxn],ff[maxn],summ[maxn]; void SPFA()
{
queue<int>Q;
while(!Q.empty()) Q.pop();
int i;
for(i=zx; i<=zd+; i++) dist[i]=-INF;
memset(ff,,sizeof(ff));
memset(summ,,sizeof(summ));
dist[zx]=;
ff[zx]=;
Q.push(zx); while(!Q.empty())
{
int hh=Q.front();
Q.pop();
summ[hh]++;
ff[hh]=;
for(i=; i<ljb[hh].size(); i++)
{
abc noww;
noww=ljb[hh][i];
if(dist[hh]+noww.costt>dist[noww.endd])
{
dist[noww.endd]=dist[hh]+noww.costt;
if(ff[noww.endd]==)
{
ff[noww.endd]=;
Q.push(noww.endd);
}
}
}
}
}
int main()
{
int i,u,v,c;
while(~scanf("%d",&n))
{
for(i=; i<maxn; i++) ljb[i].clear();
zd=-INF;
zx=INF;
tott=;
for(i=; i<n; i++)
{
scanf("%d%d%d",&u,&v,&c);
if(v>zd) zd=v;
if(u<zx) zx=u;
node[tott].startt=u;
node[tott].endd=v+;
node[tott].costt=c;
ljb[u].push_back(node[tott]);
tott++;
}
for(i=zx; i<=zd; i++)
{
node[tott].startt=i+;
node[tott].endd=i;
node[tott].costt=-;
ljb[i+].push_back(node[tott]);
tott++; node[tott].startt=i;
node[tott].endd=i+;
node[tott].costt=;
ljb[i].push_back(node[tott]);
tott++;
}
SPFA();
printf("%d\n",dist[zd+]-dist[zx]);
}
return ;
}

hdu 1384 Intervals的更多相关文章

  1. POJ 1201 &amp;&amp; HDU 1384 Intervals(差动制动系统)

    职务地址:POJ 1201   HDU 1384 依据题目意思.能够列出不等式例如以下: Sj-Si>=c; Si-S(i-1)>=0; S(i-1)-Si>=-1; 然后用最短路s ...

  2. hdu 1384 Intervals (差分约束)

    Intervals Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  3. HDU 1384 Intervals(差分约束)

    Intervals Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  4. hdu 1384 Intervals (差分约束)

    Problem - 1384 好歹用了一天,也算是看懂了差分约束的原理,做出第一条查分约束了. 题意是告诉你一些区间中最少有多少元素,最少需要多少个元素才能满足所有要求. 构图的方法是,(a)-> ...

  5. HDU 1384 Intervals &洛谷[P1250]种树

    差分约束 差分约束的裸题,关键在于如何建图 我们可以把题目中给出的区间端点作为图上的点,此处应注意,由于区间中被标记的点的个数满足区间加法,这里与前缀和类似,对于区间[L..R]来说,我们加入一条从L ...

  6. HDU 1384 Intervals【差分约束-SPFA】

    类型:给出一些形如a−b<=k的不等式(或a−b>=k或a−b<k或a−b>k等),问是否有解[是否有负环]或求差的极值[最短/长路径].例子:b−a<=k1,c−b&l ...

  7. hdu 1384 Intervals (差分约束)

    /* 给你 n 个区间 [Ai, Bi],要求从每一个区间中至少选出 Ci 个数出来组成一个序列 问:满足上面条件的序列的最短长度是多少? 则对于 不等式 f(b)-f(a)>=c,建立 一条 ...

  8. POJ 1384 Intervals (区间差分约束,根据不等式建图,然后跑spfa)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1384 Intervals Time Limit: 10000/5000 MS (Java/Others ...

  9. 差分约束 HDU - 1384 HDU - 3592 HDU - 1531 HDU - 3666

    Intervals Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

随机推荐

  1. About大数据插码

    大数据插码主要用于在用户浏览网页和填写信息后抓取对应数据,这样就可以清晰的知道每个页面有多少用户浏览过,跳出率是多少以及用户的相应信息等. 大数据插码其实很简单,主要有以下注意事项: 1.引入相应的j ...

  2. java基础练习 9

    import java.util.Scanner; public class Ninth { /*取一个整数a从右端开始的4-7位.*/ public static void main(String[ ...

  3. D3.js:交互式操作

    用户用于交互的工具一般有三种:鼠标.键盘.触屏. 1. 添加交互 对某一元素添加交互操作十分简单,代码如下: //画布大小 var width = 500, height = 500; // 在bod ...

  4. Intellij Idea + Maven + Git + Struts2 HelloWorld

    1.在intellij Idea上新建Maven项目,输入相应的groupId,artifactId,项目名称: 2.在项目的pom文件中,引入struts2的核心依赖struts2-core: &l ...

  5. openui5中的RESTful实现odata协议

    这篇文章第一次看到就一见如故,它是对过去一个时代分布式计算模型的总结,<分布式计算编程模型之RPC>:http://www.infoq.com/cn/news/2016/04/Distri ...

  6. 循序渐进看Java web日志跟踪(3)-Log4J的使用和配置

    之前说过关于java日志跟踪的几大主要用的框架,也说到了,其实在其中,Log4J充当着一个相当重要的角色.目前,大部分框架也都是采用的是Log4J,虽然说它已经停止了更新,作者也重新起了LogBack ...

  7. Zabbix 中文使用手册

    一.Zabbix简介 详情参考"企业监控利器-zabbix"http://waringid.blog.51cto.com/65148/904201. 二.Zabbix使用 2.1 ...

  8. StringBuffer使用append提示String concatenation as argument to 'StringBuffer.append()' call

    昨天发现一个IDE提示: String concatenation as argument to 'StringBuffer.append()' call less... (Ctrl+F1) Repo ...

  9. 安卓系统浏览器中select下拉按钮无法弹出选择面板奇怪问题解决

    今天遇到个让人崩溃的问题: 平台: 安卓 4.0 描述: 使用 appcan 开发 hybrid 应用,手机上点击下拉选框按钮无法弹出选择面板. 说明: 发现 webkit 内核 position:f ...

  10. 【转】http://www.cnblogs.com/yuzukwok/p/3884377.html

    来自:http://www.cnblogs.com/yuzukwok/p/3884377.html An Introduction to Xamarin.Forms 来源:http://develop ...