zoj 1508 poj 1201 Intervals
差分约束系统。
#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的更多相关文章
- poj 1201 Intervals 解题报告
Intervals Time Limit: 2000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu Submit Statu ...
- POJ 1201 Intervals || POJ 1716 Integer Intervals 差分约束
POJ 1201 http://poj.org/problem?id=1201 题目大意: 有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai, ...
- poj 1201 Intervals(差分约束)
题目:http://poj.org/problem?id=1201 题意:给定n组数据,每组有ai,bi,ci,要求在区间[ai,bi]内至少找ci个数, 并使得找的数字组成的数组Z的长度最小. #i ...
- poj 1201 Intervals——差分约束裸题
题目:http://poj.org/problem?id=1201 差分约束裸套路:前缀和 本题可以不把源点向每个点连一条0的边,可以直接把0点作为源点.这样会快许多! 可能是因为 i-1 向 i 都 ...
- POJ 1201 Intervals【差分约束】
传送门:http://poj.org/problem?id=1201 题意: 有n个如下形式的条件:,表示在区间[, ]内至少要选择个整数点.问你满足以上所有条件,最少需要选多少个点? 思路:第一道差 ...
- POJ 1201 Intervals (差分约束系统)
题意 在区间[0,50000]上有一些整点,并且满足n个约束条件:在区间[ui, vi]上至少有ci个整点,问区间[0, 50000]上至少要有几个整点. 思路 差分约束求最小值.把不等式都转换为&g ...
- poj 1201 Intervals(差分约束)
做的第一道差分约束的题目,思考了一天,终于把差分约束弄懂了O(∩_∩)O哈哈~ 题意(略坑):三元组{ai,bi,ci},表示区间[ai,bi]上至少要有ci个数字相同,其实就是说,在区间[0,500 ...
- POJ 1201 Intervals(图论-差分约束)
Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20779 Accepted: 7863 Descri ...
- 图论(差分约束系统):POJ 1201 Intervals
Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 24099 Accepted: 9159 Descri ...
随机推荐
- C#开发学习——常用的正则表达式
对于想学习正则表达式的童鞋,一些基础的语法啥的,可以参考 http://www.cnblogs.com/China3S/archive/2013/11/30/3451971.html 下边是一些我们常 ...
- Perception(0-1.1)
The perception modules run in the context of the process Cognition. They detect features in the imag ...
- docker安装使用
介绍 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互之间不会 ...
- 【LeetCode】25. Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k ...
- [Q]“获取AutoCAD安装信息时失败...”解决方法
“获取AutoCAD安装信息时失败...”解决方法:在“setup.exe”上右键,以管理员权限运行即可.
- CodeForces 709C Letters Cyclic Shift
贪心. 肯定是两个$a$之间的那些字符都$-1$,没有$a$就全部$-1$.如果输入的串全是$a$,那么把最后一个$a$改成$z$. #pragma comment(linker, "/ST ...
- NASPhoto Station不只是储存的强大照片管理功能
减少漫长的讨论时间,进而让你的艺术作品更符合客户需求.Photo Station 让你集中存储照片.随处分享及存取相簿并轻松收集朋友和客户反馈. 串流照片到大屏幕电视 DS photo 支援 Appl ...
- .net 在数据访问层中写一个DBhelper优化类
复习了在学校的时候做的WinForm端的一个学生信息管理系统,用的三层架构,看了一下里面的数据优化类 这个类是用来把对数据库的操作封装成静态方法,增删改查的时候直接调用这个类,减少项目里代码的冗余和方 ...
- excel 导入 与 导出
Excel导入 public ActionResult Excel(HttpPostedFileBase file) { HttpPostedFileBase fi ...
- angular学习笔记
1.forEach arr:参数是key,index json:与jquery相反,参数是value,key2.str-->json JSON.parse() ang ...