POJ 2101 Intervals 差分约束
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 27746 | Accepted: 10687 |
Description
Write a program that:
reads the number of intervals, their end points and integers c1, ..., cn from the standard input,
computes the minimal size of a set Z of integers which has at least ci common elements with interval [ai, bi], for each i=1,2,...,n,
writes the answer to the standard output.
Input
Output
Sample Input
5
3 7 3
8 10 3
6 8 1
1 3 1
10 11 1
Sample Output
6
Source
差分约束系统是线性规划中的一种,在一个差分约束系统中,可以看成一个矩阵乘以一个向量小于另一个向量,求其中向量两个坐标的距离关系,约束条件对的不等式和单元最短路的松弛操作十分类似!
抽象出节点,根据节点性质和题目信息建边,最短路即可。
注意一定<=建边!
如果出现负权回路说明无解!
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<functional>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
//[a,b]区间内至少有c个数在集合内,问集合最少包含多少点
//a,b 可以取0 再读入的时候手动 a++,b++
//定义ti 为[0,i]内至少有多少个数字,那么由ta-1 - tb <= -c
//由ti的定义可以推出它的性质1.ti-ti+1<=0 ti+1-ti<=1 const int MAXM = * + ;
const int MAXN = + ; struct edge
{
LL to, next, dis;
}E[MAXM];
LL head[MAXN],tot;
LL dist[MAXN];
bool vis[MAXN];
void init()
{
tot = ;
memset(head, -, sizeof(head));
}
void spfa(LL ed)
{
memset(dist, 0x3f3f3f3f, sizeof(dist));
memset(vis, false, sizeof(vis));
queue<LL> q;
q.push();
vis[] = true;
dist[] = ;
while (!q.empty())
{
LL f = q.front();
q.pop();
vis[f] = false;
for (LL i = head[f]; i != -; i = E[i].next)
{
LL v = E[i].to, d = E[i].dis;
if (dist[v] > dist[f] + d)
{
dist[v] = dist[f] + d;
if (!vis[v])
{
vis[v] = true;
q.push(v);
}
}
}
}
cout << -dist[ed] << endl;
}
void addedge(LL u, LL v, LL d)
{
E[tot].to = v;
E[tot].dis = d;
E[tot].next = head[u];
head[u] = tot++;
}
int main()
{
ios::sync_with_stdio();
init();
LL f, t, d, ed;
LL n;
cin >> n;
while (n--)
{
cin >> f >> t >> d;
f++, t++;
addedge(f - , t, -d);
ed = max(t, ed);
}
for (int i = ; i < ed; i++)
{
addedge(i, i + , );
addedge(i + , i, );
}
spfa(ed);
}
POJ 2101 Intervals 差分约束的更多相关文章
- 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 1716 Integer Intervals (差分约束 或 贪心)
Integer Intervals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12192 Accepted: 514 ...
- POJ 1201 Intervals (差分约束系统)
题意 在区间[0,50000]上有一些整点,并且满足n个约束条件:在区间[ui, vi]上至少有ci个整点,问区间[0, 50000]上至少要有几个整点. 思路 差分约束求最小值.把不等式都转换为&g ...
- POJ1201 Intervals(差分约束)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 10966 Description You ...
- hdu 1384 Intervals (差分约束)
Intervals Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- zoj 1508 Intervals (差分约束)
Intervals Time Limit: 10 Seconds Memory Limit: 32768 KB You are given n closed, integer interva ...
- poj1201 Intervals——差分约束
题目:http://poj.org/problem?id=1201 差分约束裸题: 设 s[i] 表示到 i 选了数的个数前缀和: 根据题意,可以建立以下三个限制关系: s[bi] >= s[a ...
- POJ——3169Layout(差分约束)
POJ——3169Layout Layout Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14702 Accepted ...
随机推荐
- easy ui combotree的操作
1.获取combotree的选中值 $("#id").combotree("getValue"); 2.设置combotree的选中值 $('#id').com ...
- Actionscript,AS3,MXML,Flex,Flex Builder,Flash Builder,Flash,AIR,Flash Player之关系
转自zrong's blog:http://zengrong.net/post/1295.htm ActionScript ActionScript通常简称为AS,它是Flash平台的语言.AS编写的 ...
- 到T-SQL DML 三级的阶梯:在SQL server中实现关系模型
作者: Gregory Larsen, 2017/08/02 (第一次出版: 2011/11/09) 翻译:谢雪妮,许雅莉,赖慧芳,刘琼滨 译文: 系列 该文章是阶梯系列的一部分:T-SQL DML的 ...
- Farseer.net轻量级ORM开源框架 V1.3版本升级消息
SHA-1: abca3b99801648fa23c7f4934de6c128f042cf47 * 提交新版本:V1.31.重构:FS.Mapping命名空间移到 FS.Core.Map中2.重构:对 ...
- -webkit/IE/Firefox的一些样式
仅限于-webkit的样式特效:-webkit-overflow-scrolling:touch;滚动时回弹效果:如果出现偶尔卡住不动的情况,那么在使用该属性的元素上不设置定位或者手动设置定位为sta ...
- 迅为IMX6Q四核核心板商业级|工业级|IMX6Plus版本|IMX6DL双核核心板
IMX6Q处理器:兼容单核,双核,工业级,汽车级,IMX6Q最新Plus版本,共用同一底板,高端产品无忧. i.MX6系列针对消费电子.工业控制和汽车应用领域,它将ARM Cortex-A9架构的高功 ...
- 安装gitlab并配置邮箱
安装要求:运行内存必须大于等于2G 一.安装docker wget -qO- https://get.docker.com/ | sh 镜像加速: echo '{"registry-mirr ...
- CAD交互绘制虚线(com接口)
用户可以在控件视区任意位置绘制直线. 主要用到函数说明: _DMxDrawX::DrawLine 绘制一个直线.详细说明如下: 参数 说明 DOUBLE dX1 直线的开始点x坐标 DOUBLE dY ...
- D2. Toy Train
D2. Toy Train time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Filter简介
Filter也称之为过滤器,它是Servlet技术中最激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servlet, 静态图片文件或静态 htm ...