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 ...
随机推荐
- [React] React Fundamentals: Mixins
Mixins will allow you to apply behaviors to multiple React components. Components are the best way t ...
- HDU-1002(简单大数加法)
A + B Problem II Problem Description I have a very simple problem for you. Given two integers A and ...
- js 获取当前时间格式怎么转换?
toLocaleDateString() 得到的时间是 yyyy年MM月dd日 HH:ss:mm 格式的,怎么转换成yyyy-MM-dd HH:ss:mm 在js里面 仅针对这个问题来说,不需要那么大 ...
- RabbitMQ 原文译05--Topics
在之前的系统中,我们改进了我们的日志系统,我们使用direct 交换机代替fanout交换机,可以实现选择性的接受日志. 虽然使用direct 交换机改进了我们的系统,但是对于多种条件的判断,依然存在 ...
- [理解ASP.NET Core框架]一个五十行的控制台Web
在阅读了Artech的ASP.NET Core管道深度剖析(2):创建一个“迷你版”的管道来模拟真实管道请求处理流程之后, 自己做了一个"迷你版"中的"迷你版" ...
- Asp.Net Core简单整理
1.Asp.NetCore 中文入门文档 http://www.cnblogs.com/dotNETCoreSG/p/aspnetcore-index.html
- 学习笔记_Java_day12_Cookie
Cookie 1 Cookie概述 1.1 什么叫Cookie Cookie翻译成中文是小甜点,小饼干的意思.在HTTP中它表示服务器送给客户端浏览器的小甜点.其实Cookie就是一个键和一个值构成的 ...
- Java—static、this、super用法总结
通过用static来定义方法或成员,为我们编程提供了某种便利,从某种程度上可以说它类似于C语言中的全局函数和全局变量.(理解为加了static的就是全局变量)但是,并不是说有了这种便利,你便可 ...
- TMemIniFile 与TIniFile 区别
在uses 申明 Inifiles MyStream:TMemIniFile; MyStream:=TMemIniFile.Create('c:\proxy.ini'); memo1.Text:=My ...
- Cookie / Session / URL重写
Cookie //创建一个Cookie对象 Cookie cookie = new Cookie("username","JACK"); //在客户端存储的时间 ...