差分约束系统。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn = ; map<int, int> jz[maxn];
vector<int>ljb[maxn];
int dist[maxn],flag[maxn];
int mm, mx; void spfa()
{
int ii;
queue<int>Q;
memset(flag, , sizeof(flag));
flag[mx] = ;
for (ii = ; ii <= mx; ii++) dist[ii] = ;
dist[mx] = ; Q.push(mx);
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]] = ;
}
}
}
} }
} int main()
{
int i, n, a, b, c;
while (~scanf("%d", &n))
{
for (i = ; i <= ; i++) jz[i].clear();
for (i = ; i <= ; i++) ljb[i].clear();
mx = -, mm = ;
for (i = ; i < n; i++)
{
scanf("%d%d%d", &a, &b, &c);
ljb[b].push_back(a - );
jz[b][a - ] = -c;
if (a < mm) mm = a;
if (b > mx) mx = b;
}
for (i = ; i <= mx; i++)
{
ljb[i - ].push_back(i);
jz[i - ][i] = ;
ljb[i].push_back(i - );
jz[i][i - ] = ;
}
spfa();
printf("%d\n", dist[mx] - dist[mm - ]);
}
return ;
}

zoj 1508 poj 1201 Intervals的更多相关文章

  1. poj 1201 Intervals 解题报告

    Intervals Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %llu Submit Statu ...

  2. POJ 1201 Intervals || POJ 1716 Integer Intervals 差分约束

    POJ 1201 http://poj.org/problem?id=1201 题目大意: 有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai, ...

  3. poj 1201 Intervals(差分约束)

    题目:http://poj.org/problem?id=1201 题意:给定n组数据,每组有ai,bi,ci,要求在区间[ai,bi]内至少找ci个数, 并使得找的数字组成的数组Z的长度最小. #i ...

  4. poj 1201 Intervals——差分约束裸题

    题目:http://poj.org/problem?id=1201 差分约束裸套路:前缀和 本题可以不把源点向每个点连一条0的边,可以直接把0点作为源点.这样会快许多! 可能是因为 i-1 向 i 都 ...

  5. POJ 1201 Intervals【差分约束】

    传送门:http://poj.org/problem?id=1201 题意: 有n个如下形式的条件:,表示在区间[, ]内至少要选择个整数点.问你满足以上所有条件,最少需要选多少个点? 思路:第一道差 ...

  6. POJ 1201 Intervals (差分约束系统)

    题意 在区间[0,50000]上有一些整点,并且满足n个约束条件:在区间[ui, vi]上至少有ci个整点,问区间[0, 50000]上至少要有几个整点. 思路 差分约束求最小值.把不等式都转换为&g ...

  7. poj 1201 Intervals(差分约束)

    做的第一道差分约束的题目,思考了一天,终于把差分约束弄懂了O(∩_∩)O哈哈~ 题意(略坑):三元组{ai,bi,ci},表示区间[ai,bi]上至少要有ci个数字相同,其实就是说,在区间[0,500 ...

  8. POJ 1201 Intervals(图论-差分约束)

    Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20779   Accepted: 7863 Descri ...

  9. 图论(差分约束系统):POJ 1201 Intervals

    Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24099   Accepted: 9159 Descri ...

随机推荐

  1. html - table 表格不被撑开,td某些列宽度固定某些列自适应

    table-layout 属性的解释:http://www.w3school.com.cn/cssref/pr_tab_table-layout.asp 1,实现table细边框,设置如下css: t ...

  2. CodeForces 749D Leaving Auction

    二分查找,$set$. 对于某一次询问,如果把人删光了,那么输出$0$ $0$. 如果只剩下$1$个人,那么输出那个人喊的最低价格. 如果剩下的人数有大于等于两个, 这时最底下出现的情景必然是红色部分 ...

  3. 【完全背包】HDU 4508 湫湫系列故事——减肥记I

    Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Submission(s) ...

  4. 3.使用secureCRT连接PC,LINUX,开发板

    1.设置secureCRT(可选项):http://www.linuxyw.com/linux/gongxiang/20130505/161.html 2.使用secureCRT远程登录linux 3 ...

  5. GOPS2017全球运维大会 • 深圳站 历届金牌讲师精选亮相

    GOPS2017全球运维大会 • 深圳站将于2017年4月21日-22日在深圳举行,GOPS2017报名平台:活动家! 快捷报名通道:http://www.huodongjia.com/event-2 ...

  6. mysql中timestamp的自动生成与更新

    转自:mysql中timestamp的自动生成与更新 MYSQL中TIMESTAMP类型可以设定默认值,就像其他类型一样.1.自动UPDATE 和INSERT 到当前的时间:表:----------- ...

  7. 查看Oracle正在执行的任务

    select a.program, b.spid, c.sql_text,c.SQL_ID from v$session a, v$process b, v$sqlarea c where a.pad ...

  8. C++类与static

    到目前为止,我们设计的类中所有的成员变量和成员函数都是属于对象的,如我们在前面定义的book类,利用book类声明两个对象Alice和Harry,这两个对象均拥有各自的price和title成员变量, ...

  9. kindeditor编辑器上传图片失败 错误 405.0解决办法(亲测)

    HTTP 错误 405.0 - Method Not Allowed(省略)editor/php/upload_json.php?dir=image物理路径 http://www.gdgoga.com ...

  10. 使用inno setup制作安装包