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 ...
随机推荐
- sharepoint 2013 更改搜索server组态
1.新搜索server在.安装sharepoint server 2013,并连接到一个现有的sharepoint server领域,完成后.您可以配置新的搜索server. 打开sharepoint ...
- linux-memory-buffer-vs-cache
http://stackoverflow.com/questions/6345020/linux-memory-buffer-vs-cache
- careercup-树与图 4.7
4.7 设计并实现一个算法,找出二叉树中某两个结点的第一个共同祖先.不得将额外的结点储存在另外的数据结构中.注意:这不一定是二叉查找树. 解答 本题的关键应当是在Avoid storing addit ...
- ASP.NET 未被授权访问所请求的资源。请考虑授予 ASP.NET 请求标识访问此资源的权限
开发了一个导入TXT文件的功能,执行过程中出错.提示:.....ASP.NET 未被授权访问所请求的资源.请考虑授予 ASP.NET 请求标识访问此资源的权限.ASP.NET 有一个在应用程序没有模拟 ...
- cocos2d-x之CCMotionStreak类——2013-08-25 16
在游戏的实现过程中,有时会需要在某个游戏对象上的运动轨迹上实现渐隐效果.这种感觉就好像是类似飞机拉线的拖尾巴,在视觉上感觉很好,比如子弹的运动轨迹等,如果不借助引擎的帮助,这种效果往往需要通过大量 ...
- PHP中将数据库中的数据显示在网页
最近没事把以前的东西感觉还可以的又简单的看了以下,因为还在学习新的东西,所以,发表的博客也不是很多,也许是有感而发吧. 这次讲的是mysql数据库中的数据使用php如何显示在网页中.首先,先建好自己的 ...
- install lua client for redis-server on Mac
1. lua client library for redis-server https://github.com/nrk/redis-lua 2. dependent luasocket https ...
- Java并发——ReentrantLock类源码阅读
ReentrantLock内部由Sync类实例实现. Sync类定义于ReentrantLock内部. Sync继承于AbstractQueuedSynchronizer. AbstractQueue ...
- centos 下安装ati显卡驱动方法
1)到ati的官网(http://support.amd.com/us/gpudownload/Pages/index.aspx)下载相应的驱动,一定要注意 radeon系列和mobility rad ...
- 推荐几个对Asp.Net开发者比较实用的工具
推荐几个对Asp.Net开发者比较实用的工具.大家有相关工具也可以在评论区留言,一起努力学习. 工具 1.Visual stdio Productivity Power tool:visual std ...