POJ 1716 Integer Intervals 差分约束
题目:http://poj.org/problem?id=1716
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue> const int INF = 0x3f3f3f3f; struct Edge
{
int v, w;
Edge(){};
Edge(int v, int w)
{
this->v = v;
this->w = w;
}
}; std::vector<Edge>map[];
int dist[];
bool inque[]; void spfa(int s)
{
std::queue<int>q;
memset(inque, , sizeof(inque));
dist[s] = ;
q.push(s);
inque[s] = ;
while(!q.empty())
{
int u = q.front();
q.pop();
inque[u] = ;
for(int i = ; i < map[u].size(); i++)
{
int v = map[u][i].v;
if(dist[v] < dist[u] + map[u][i].w)
{
dist[v] = dist[u] + map[u][i].w;
if(!inque[v])
{
q.push(v);
inque[v] = ;
}
}
}
}
} int main()
{
int n;
int x, y;
while(scanf("%d", &n) != EOF)
{
for(int i = ; i <= ; i++)
{
map[i].clear();
}
int low = INF, high = ;
for(int i = ; i < n; i++)
{
scanf("%d %d", &x, &y);
map[x].push_back(Edge(y+, ));
if(low > x)low = x;
if(high < y)high = y;
}
for(int i = low; i <= high+; i++)
{
map[].push_back(Edge(i, ));
map[i].push_back(Edge(i+, ));
map[i+].push_back(Edge(i, -));
dist[i] = -INF;
}
map[].push_back(Edge(high+, ));
spfa(low);
printf("%d\n", dist[high+] - dist[low]);
}
return ;
}
POJ 1716 Integer Intervals 差分约束的更多相关文章
- poj 1716 Integer Intervals (差分约束 或 贪心)
Integer Intervals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12192 Accepted: 514 ...
- POJ 1201 Intervals || POJ 1716 Integer Intervals 差分约束
POJ 1201 http://poj.org/problem?id=1201 题目大意: 有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai, ...
- poj 1716 Integer Intervals(差分约束)
1716 -- Integer Intervals 跟之前个人赛的一道二分加差分约束差不多,也是求满足条件的最小值. 题意是,给出若干区间,需要找出最少的元素个数,使得每个区间至少包含两个这里的元素. ...
- POJ 1716 Integer Intervals
题意:给出一些区间,求一个集合的长度要求每个区间里都至少有两个集合里的数. 解法:贪心或者差分约束.贪心的思路很简单,只要将区间按右边界排序,如果集合里最后两个元素都不在当前区间内,就把这个区间内的最 ...
- POJ 1716 Integer Intervals#贪心
(- ̄▽ ̄)-* //求一个集合,这个集合与任意一个区间的交集,需至少有两个数字 //贪心过程:按n个区间的最右值从小到大对区间进行排列, //集合首先取第一个区间的最右两个数字, //到第二个区间, ...
- 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 2101 Intervals 差分约束
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 27746 Accepted: 10687 Description You ...
- POJ 3159 Candies(差分约束,最短路)
Candies Time Limit: 1500MS Memory Limit: 131072K Total Submissions: 20067 Accepted: 5293 Descrip ...
随机推荐
- SilkTest天龙八部系列3-动态父窗口
SilkTest中用parent语句来声明某个window的父窗口,这会帮助silktest在识别该对象时检查其是否是由该父窗口打开,如果parent语句申明的父窗口并不存在,那么该对象无法被正确识别 ...
- Redis学习手册(String数据类型)
一.概述: 字符串类型是Redis中最为基础的数据存储类型,它在Redis中是二进制安全的,这便意味着该类型可以接受任何格式的数据,如JPEG图像数据或Json对象描述信息等.在Redis中字符串类型 ...
- QT运行时加载UI文件
写QT程序里运行时加载UI文件,代码如下: 点击(此处)折叠或打开 #include "keyboard.h" #include <QtUiTools> #incl ...
- Java开发之I/O读取文件实例详解
在java开发或者android开发中,读取文件是不可避免的,以下对java开发中读取文件做了归纳和详解: 1.按字节读取文件内容2.按字符读取文件内容3.按行读取文件内容 4.随机读取文件内容 pa ...
- Java基础知识强化之IO流笔记62:三种方式实现键盘录入
1. 三种方式实现键盘录入 System.in 标准输入流.是从键盘获取数据的 键盘录入数据三种方式: A:main方法的args接收参数. java HelloWorld hello w ...
- 布隆过滤器(Bloom Filter)
一.布隆过滤器介绍 Bloom Filter是一种空间效率很高的随机数据结构,Bloom Filter可以看做是对bit-map的扩展,它的原理如下: 当一个元素被加入集合时,通过K个Hash函数将这 ...
- how to forget about delta cycles for RTL design
A delta cycle is a VHDL construct used to makeVHDL, a concurrent language, executable on asequential ...
- Nginx 简单的负载均衡配置示例
http://www.cnblogs.com/xiaogangqq123/archive/2011/03/02/1969006.html 在此记录下Nginx服务器nginx.conf的配置文件说明, ...
- Devexpress 使用经验 —— ASPxGridView命令行自定义按钮灵活使用
ASPX <dx:ASPxGridView ID="ASPxGridView1" runat="server" DataSourceID="Ob ...
- C#微信公众号开发 -- (七)自定义菜单事件之VIEW及网页(OAuth2.0)授权
通俗来讲VIEW其实就是我们在C#中常用的a标签,可以直接在自定义菜单URL的属性里面写上需要跳转的链接,也即为单纯的跳转. 但更多的情况下,我们是想通过VIEW来进入指定的页面并进行操作. 举一个简 ...