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 ...
随机推荐
- Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FileUtils
1.错误叙述性说明 警告: Could not create JarEntryRevision for [jar:file:/D:/MyEclipse/apache-tomcat-7.0.53/web ...
- TRUNCATE TABLE 与 DELETE table 区别
语法 TRUNCATE TABLE name;参数 TRUNCATE TABLE 在功能上与不带 WHERE 子句的 DELETE 语句相同:二者均删除表中的全部行. TRUNCATE TABLE ...
- 集合练习——List部分
利用ArrayList 1.存储多个员工信息,包括工号,姓名,年龄,入职时间,逐条打印所有员工姓名,并输出员工个数. package CollectionPart; import java.util. ...
- Struts---- <s:bean>标签
近几天学习的都是跟struts有关的.详细写<s:bean>标签 具体内容为: 一.准备工作 1.新建Web工程 2.添加struts:右键点击工程名选择My Eclipse-->点 ...
- 通过配置tomcat虚拟路径配置站点的静态资源
我们常常站点中会提供给用户上传文件.图片.视频或者诸如为了提高性能生成的静态文件等存储在站点应用中.但如果静态资源文件和项目文件在同一个目录下,当我们重新部署文件时,war重新解压会导致静态资源文件的 ...
- C#Combobox显示名称保存代码
private void Form1_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add ...
- jquery操作iframe中的js函数
关键字:jquery操作iframe中的js函数 1.jquery操作iframe中的元素(2种方式) var tha = $(window.frames["core_content&quo ...
- union的用法
union的用法 union用来连接两个查询语句,把两个查询语句的查询结果合并起来,两个查询语句的查询字段个数必须一样,否则会出错,查询的字段可以不一样,类型也可以不一样,但是这样查询的意义不大,如果 ...
- 16Aspx.com源码2014年7月详细
Web电子商务网(三层)V2.0源码 2014-07-31 [VS2010] 源码介绍: Web电子商务网(三层)V2.0源码 源码描述: 一.源码特点 采用三层架构开发, ...
- Spring.net架构示例(含Aop和Ioc)源码
最近写了一个Spring.net的架构. 一.架构主图 架构图的数据流程走向是: UI层=>UILogic>=>Service>Business=>DataAccess ...