Hdu 1384(差分约束)
Intervals
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2931 Accepted Submission(s): 1067Problem DescriptionYou are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn.Write a program that:
> reads the number of intervals, their endpoints 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
InputThe
first line of the input contains an integer n (1 <= n <= 50 000) -
the number of intervals. The following n lines describe the intervals.
The i+1-th line of the input contains three integers ai, bi and ci
separated by single spaces and such that 0 <= ai <= bi <= 50
000 and 1 <= ci <= bi - ai + 1.Process to the end of file.
OutputThe
output contains exactly one integer equal to the minimal size of set Z
sharing at least ci elements with interval [ai, bi], for each i = 1, 2,
..., n.Sample Input5
3 7 3
8 10 3
6 8 1
1 3 1
10 11 1Sample Output6
/*************************************************************************
> File Name: 1384.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年08月26日 星期二 08时59分19秒
> Propose:
************************************************************************/
#include <queue>
#include <cmath>
#include <string>
#include <cstdio>
#include <vector>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ const int INF = 0x3f3f3f3f;
const int MAX_N = ;
typedef pair<int, int> pii;
vector<pii> G[MAX_N];
int n, d[MAX_N];
bool inq[MAX_N]; void AddEdge(int u, int v, int w) {
G[u].push_back(pii(v, w));
} void spfa(int s) {
queue<int> Q;
memset(d, 0x3f, sizeof(d));
memset(inq, false, sizeof(inq));
d[s] = ;
inq[s] = true;
Q.push(s);
while (!Q.empty()) {
int u = Q.front(); Q.pop(); inq[u] = false;
for (int i = ; i < G[u].size(); i++) {
int v = G[u][i].first, w = G[u][i].second;
if (d[u] + w < d[v]) {
d[v] = d[u] + w;
if (!inq[v]) Q.push(v), inq[v] = true;
}
}
}
} int main(void) {
while (~scanf("%d", &n)) {
for (int i = ; i <= ; i++) G[i].clear();
int s = INF, t = -;
for (int i = ; i < n; i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
b++;
s = min(s, a); t = max(t, b);
AddEdge(b, a, -c);
}
for (int i = s; i < t; i++) AddEdge(i, i + , ), AddEdge(i + , i, ); spfa(t); printf("%d\n", -d[s]);
} return ;
}
Hdu 1384(差分约束)的更多相关文章
- hdu 1531(差分约束)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1531 差分约束的题之前也碰到过,刚好最近正在进行图论专题的训练,就拿来做一做. ①:对于差分不等式,a ...
- I - 动物狂想曲 HDU - 6252(差分约束)
I - 动物狂想曲 HDU - 6252 雷格西桑和路易桑是好朋友,在同一家公司工作.他们总是一起乘地铁去上班.他们的路线上有N个地铁站,编号从1到N.1站是他们的家,N站是公司. 有一天,雷格西桑起 ...
- hdu 4598 差分约束
思路:首先就是判断是否有奇环,若存在奇环,则输出No. 然后用差分约束找是否符合条件. 对于e(i,j)属于E,并且假设顶点v[i]为正数,那么v[i]-v[j]>=T--->v[j]-v ...
- HDOJ 1384 差分约束
结题报告合集请戳:http://972169909-qq-com.iteye.com/blog/1185527 /*题意:求符合题意的最小集合的元素个数 题目要求的是求的最短路, 则对于 不等式 f( ...
- hdu 3666(差分约束,手动栈解决超时问题)
THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 1364(差分约束)
King Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12056 Accepted: 4397 Description ...
- hdu 1534(差分约束+spfa求最长路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1534 思路:设s[i]表示工作i的开始时间,v[i]表示需要工作的时间,则完成时间为s[i]+v[i] ...
- hdu 3440 差分约束
看完题目第一遍,感觉很简单.当写完程序跑测试用例的时候,发现第二个总是过不了,然后好好研究了一下测试用例,才知道原来不是程序有问题,而是我的建图方式错了.对于这些无序的点,如果高的在右边,不等式是di ...
- hdu 1534(差分约束)
Schedule Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 3440(差分约束好题)
House Man Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- 读《深入PHP 面向对象、模式与实践》笔记
1. include() 和require() 语句的不同在于它们如何处理错误.使用require()调用文件发生错误时,将会停止整个程序;调用include()时遇到相同的错误,则会生成警告并停止执 ...
- P3480 [POI2009]KAM-Pebbles
P3480 [POI2009]KAM-Pebbles比如第一个样例 原:0 2 2差: 2 0 0如果把中间的2拿掉一个,就会变成原:0 1 2差: 1 1 0就可以把差看成阶梯nim细节:最终要移到 ...
- unordered_map
#include <iostream> #include <cstdio> #include <queue> #include <algorithm> ...
- LUOGU P2580 于是他错误的点名开始了(trie树)
传送门 解题思路 trie树模板
- TCP/IP四层模型和OSI七层模型(模型分层的作用是什么)
TCP/IP四层模型和OSI七层模型的概念(模型分层的作用是什么) 一.总结 一句话总结: 减轻问题的复杂程度,一旦网络发生故障,可迅速定位故障所处层次,便于查找和纠错: 在各层分别定义标准接口,使具 ...
- 密码学笔记(2)——RSA密码
上一篇笔记中讲述了大量的代数知识,这一篇中我们看看如何将这些代数知识应用到RSA密码体制中. 一.公钥密码学简介 在经典密码学的研究模型中,我们根据已选择的秘钥K得到一条加密规则$e_{k}$和一条解 ...
- 如何提高Axure设计的效率 提高Axure设计效率的10条建议
如何更有效率的使用axure,这是新手需要掌握的技能.本文作者从实际经验中归纳出来的十条建议十分值得学习,转载分享给大家: Axure 是创建软件原型的快速有力的工具.上手很容易,但是,其中存在一个危 ...
- pycharm使用教程链接+部分练习题01
pycharm安装: https://www.cnblogs.com/jin-xin/articles/9811379.html pycharm使用教程: https://edu.51cto.com/ ...
- C# GDI+编程(二)
常用的绘图函数 DrawArc绘制一个弧形 示例:graphics.DrawArc(pen,,,,,,) 倒数第二个参数,表示起始度数,最后一个参数是弧形的跨越度数.比如起始度数是90,跨越度数是12 ...
- [Swoole系列入门教程 4] 定时器与心跳demo