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 ...
随机推荐
- 03.MyBatis的核心配置文件SqlMapConfig.xml
SqlMapConfig.xml中配置的内容和顺序如下: properties(属性) settings(全局配置参数) typeAliases(类型别名) typeHandlers(类型处理器) o ...
- CSS3 学习笔记(动画 多媒体查询)
动画 1.@keyframes规则用于创建动画.在@keyframes中规定某项CSS样式,就能创建由当前样式逐渐改为新样式的动画效果 2.使用animation进行动画捆绑.两个值:动画名称.时长 ...
- 使用Ajax获取多选框用户选择的值问题
目录 说明 正文 说明 在web开发过程中,将多选框的值提交到django后台,有两种提交方式: form表单提交 ajax异步提交 我需要使用ajax将复选框的值提交到后台,记录一下当时碰到的问题 ...
- Intel RealSense Depth Camera D435安装ROS 驱动——Ubuntu16.04
官方教程 软件包下载链接 https://github.com/IntelRealSense/realsense-ros Download/Clone librealsense github repo ...
- 平衡树模板【splay的实现】
[平衡树splay实现] 无注释代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; ,MAXN=1e ...
- MYSQL常用命令(转)
1.导出整个数据库mysqldump -u 用户名 -p --default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin1)mysqldum ...
- springmvc-@RequestBody无法映射首字母大写的属性
@RequestBody可以将前台传入的json格式数据自动映射成对象,当如果属性的首字母大写,则会出现不能映射的情况,如: private String ICCID;会出现映射失败的情况 解决办法: ...
- vue 实现单选框
参考:https://blog.csdn.net/qq_42221334/article/details/81630634 效果: vue: <template> <div> ...
- HBase与传统关系数据库的对比分析
- Errors were encountered while processing: mysql-server-5.5
ubuntu 中运行完sudo apt-get install curl之后,最后出现: ldconfig deferred processing now taking place Errors we ...