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 ...
随机推荐
- 微信小程序入门——怎么建多个项目?(导入官方Demo程序进行学习)
昨天1月9日微信小程序发布,顿时被朋友圈刷爆,今天看了一下官方文档,自己开始一步一步搭建环境体验小程序开发. 常见问题: 1.微信小程序开发是否需要重新创建开发者账号? 需要,即使之前申请了微信服务号 ...
- 在SQL SERVER中查找用分隔符分隔的数据
SELECT * FROM [DB_SCJC].[dbo].[tn_Manager] 其中, CHARINDEX({1},{2})中,{1}是要查找的字符,{2}是字典库.返回值为{1}在{2}中的位 ...
- Intellij Idea + Maven + Git + Struts2 HelloWorld
1.在intellij Idea上新建Maven项目,输入相应的groupId,artifactId,项目名称: 2.在项目的pom文件中,引入struts2的核心依赖struts2-core: &l ...
- Mysql之CentOS初探
1. 卸载mysql 查看CentOS是否已经安装mysql数据库 rpm -qa | grep mysqlrpm -qa | grep MySQL 如果有,则卸载 // --nodeps表示强制rp ...
- Python基础之字符串
字符串内置处理函数 1.capitalize() 描述: 将字符串的第一个字母变成大写,其他字母变小写. 示例: a= "hello world" print (a.capital ...
- usaco月赛,2017.1总结
T1:跳舞的奶牛 大致题意:一个体积为k的舞台能够同时容纳k只奶牛一起跳舞,他们每头奶牛的跳舞时间不同,如果有一只奶牛跳完了第k+1头奶牛就会立刻上场跳舞,当所有奶牛跳完舞以后我们认为这次表演结束.现 ...
- express mongoose 新手上路 问题记录
1.npm start启动报错,提示端口占用 app.js中添加了app.listen(3000),删掉即可 2.跳转到html页面 //ejs改为html app.engine('.html', r ...
- Attempt to write to field 'android.support.v4.app.FragmentManagerImpl android.support.v4.app.Fragment.mFragmentManager' on a null object reference
E/AndroidRuntime﹕ FATAL EXCEPTION: mainProcess: org.example.magnusluca.drawertestapp, PID: 3624java. ...
- AppCan 双击返回按钮退出应用
使用AppCan开发手机应用,拦截返回键实现自定义2秒内双击退出应用的操作 var c1c = 0; window.uexOnload = function(type){ uexWindow.setR ...
- excel 导入 与 导出
Excel导入 public ActionResult Excel(HttpPostedFileBase file) { HttpPostedFileBase fi ...